Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle old given syntax where identifier and type are seperated by new line #21957

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +1010,25 @@ object Parsers {
skipParams()
lookahead.isColon
&& {
lookahead.nextToken()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the lookahead.nextToken() to line 1018, just before
!lookahead.isAfterLineEnd. That saves us a useless nextToken when source is 3.6.

!sourceVersion.isAtLeast(`3.6`)
|| { // in the new given syntax, a `:` at EOL after an identifier represents a single identifier given
// Example:
// given C:
// 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 = ???
}
Loading