Skip to content

Commit 9fc21f9

Browse files
committed
Disambiguate more towards new given syntax, show solution for scala#15840
Faced with given C[T]: ... (with a new line after `:`) we now classify this as new given syntax, and assume ... is a template body. If one wants to use old syntax, one can still write given C[T] : ImplementedType ... # Conflicts: # compiler/src/dotty/tools/dotc/parsing/Parsers.scala
1 parent 5be4be4 commit 9fc21f9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ object Parsers {
965965
lookahead.isColon
966966
&& {
967967
!in.featureEnabled(Feature.modularity)
968-
|| paramsSeen
969968
|| { // with modularity language import, a `:` at EOL after an identifier represents a single identifier given
970969
// Example:
971970
// given C:

tests/run/i15840.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//> using options -language:experimental.modularity -source future
2+
3+
trait Nat:
4+
type N <: Nat
5+
6+
class _0 extends Nat:
7+
type N = _0
8+
9+
class NatOps[N <: Nat](tracked val n: N):
10+
def toInt(using toIntN: ToInt[n.N]): Int = toIntN()
11+
12+
// works
13+
def toInt[N <: Nat](n: N)(using toIntN: ToInt[n.N]) = toIntN()
14+
15+
sealed abstract class ToInt[N <: Nat]:
16+
def apply(): Int
17+
18+
object ToInt:
19+
given ToInt[_0] {
20+
def apply() = 0
21+
}
22+
23+
@main def Test() =
24+
assert(toInt(new _0) == 0)
25+
assert(NatOps[_0](new _0).toInt == 0)
26+
assert:
27+
NatOps(new _0).toInt == 0 // did not work

0 commit comments

Comments
 (0)