diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index cd727ba8ac72..7a55690dcc21 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1017,6 +1017,18 @@ object Parsers { // def f = ... lookahead.nextToken() !lookahead.isAfterLineEnd + } || { + // Support for for pre-3.6 syntax where type is put on the next line + // Examples: + // given namedGiven: + // X[T] with {} + // given otherGiven: + // X[T] = new X[T]{} + lookahead.isIdent && { + lookahead.nextToken() + skipParams() + lookahead.token == WITH || lookahead.token == EQUALS + } } } diff --git a/tests/pos/i21768.scala b/tests/pos/i21768.scala new file mode 100644 index 000000000000..85066d0cb8a6 --- /dev/null +++ b/tests/pos/i21768.scala @@ -0,0 +1,12 @@ + +trait Foo[T]: + def foo(v: T): Unit + +given myFooOfInt: + Foo[Int] with + def foo(v: Int): Unit = ??? + +given myFooOfLong: + Foo[Long] = new Foo[Long] { + def foo(v: Long): Unit = ??? + }