Skip to content

Commit 7644ecd

Browse files
Handle old given syntax where identifier and type are seperated by new line (scala#21957)
Fixes scala#21768 Fixes usages of `with {...}` and `= new {}` declarations presented in tests.
1 parent 2a62152 commit 7644ecd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,18 @@ object Parsers {
10171017
// def f = ...
10181018
lookahead.nextToken()
10191019
!lookahead.isAfterLineEnd
1020+
} || {
1021+
// Support for for pre-3.6 syntax where type is put on the next line
1022+
// Examples:
1023+
// given namedGiven:
1024+
// X[T] with {}
1025+
// given otherGiven:
1026+
// X[T] = new X[T]{}
1027+
lookahead.isIdent && {
1028+
lookahead.nextToken()
1029+
skipParams()
1030+
lookahead.token == WITH || lookahead.token == EQUALS
1031+
}
10201032
}
10211033
}
10221034

tests/pos/i21768.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
trait Foo[T]:
3+
def foo(v: T): Unit
4+
5+
given myFooOfInt:
6+
Foo[Int] with
7+
def foo(v: Int): Unit = ???
8+
9+
given myFooOfLong:
10+
Foo[Long] = new Foo[Long] {
11+
def foo(v: Long): Unit = ???
12+
}

0 commit comments

Comments
 (0)