Skip to content

Precedence of old vs new given syntax in case of ambiguity #22291

Open
@SrTobi

Description

@SrTobi

Compiler version

3.6.2

Minimized example

trait A

object Test {
  given A    // declaration in 3.5, definition in 3.6
  given a: A // declaration in 3.5 and 3.6
}

Output

In 3.6.2:

Compiling project (Scala 3.6.2, JVM (21))
[error] ./test.scala:7:9
[error] Declaration of given instance a not allowed here: only classes can have declared but undefined members
[error]   given a: A
[error]     

In 3.5.2:

Compiling project (Scala 3.5.2, JVM (21))
[error] ./test.scala:7:1
[error] anonymous given cannot be abstract
[error]   given a: A
[error] ^^^^^
[error] ./test.scala:6:9
[error] Declaration of given instance given_A not allowed here: only classes can have declared but undefined members
[error]   given A
[error]         ^
[error] ./test.scala:7:9
[error] Declaration of given instance a not allowed here: only classes can have declared but undefined members
[error]   given a: A
[error]         ^

Expectation

Hi,
I'm still implementing the new/old given syntax in Intellij and I'm slightly confused what's the correct way to parse the above code with the new syntax.
Both givens are allowed under both grammar rules (grammar is ambiguous), but it seems that given A is parsed as a declaration in 3.5 and definition in 3.6, while given a: A is parsed as a declaration in both versions...
From what I can see given a: A should be a definition in 3.6, too. Or does the old syntax take precedence over the new syntax... but then given A should be a declaration in 3.6 as well 😕

(also note that the anonymous given cannot be abstract message is on the wrong given?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions