Skip to content

Fix #6864: Fix parsing problem for consecutive anonymous givens #6907

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

Merged
merged 2 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2338,20 +2338,24 @@ object Parsers {
(ofClass || ofInstance) && {
val lookahead = in.lookaheadScanner // skips newline on startup
lookahead.nextToken() // skip the `given`
if (lookahead.token == IDENTIFIER || lookahead.token == BACKQUOTED_IDENT) {
lookahead.nextToken()
if (lookahead.token == LBRACKET) {
if (lookahead.token == LBRACKET) true
else {
if (lookahead.token == IDENTIFIER && lookahead.name != nme.as ||
lookahead.token == BACKQUOTED_IDENT) {
lookahead.nextToken()
var openBrackets = 1
while (openBrackets > 0 && lookahead.token != EOF) {
if (lookahead.token == LBRACKET) openBrackets += 1
else if (lookahead.token == RBRACKET) openBrackets -= 1
if (lookahead.token == LBRACKET) {
lookahead.nextToken()
var openBrackets = 1
while (openBrackets > 0 && lookahead.token != EOF) {
if (lookahead.token == LBRACKET) openBrackets += 1
else if (lookahead.token == RBRACKET) openBrackets -= 1
lookahead.nextToken()
}
}
}
lookahead.token == FOR ||
lookahead.token == IDENTIFIER && lookahead.name == nme.as
}
lookahead.token == FOR ||
lookahead.token == IDENTIFIER && lookahead.name == nme.as
}

def recur(firstClause: Boolean, nparams: Int, contextualOnly: Boolean): List[List[ValDef]] = {
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i6864.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class A
class B

given as A
given as B

trait Foo
trait Bar

given as Foo
given as Bar

trait C
trait Baz[A]

given as C
given [A] as Baz[A]