Skip to content

Commit

Permalink
Backport "Handle old given syntax where identifier and type are seper…
Browse files Browse the repository at this point in the history
…ated by new line" to 3.6 (#21964)

Backports #21957 to the 3.6.2.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Nov 18, 2024
2 parents c20a294 + 472de25 commit 2482c5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,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
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i21768.scala
Original file line number Diff line number Diff line change
@@ -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 = ???
}

0 comments on commit 2482c5d

Please sign in to comment.