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

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

Open
SrTobi opened this issue Jan 2, 2025 · 2 comments
Open

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

SrTobi opened this issue Jan 2, 2025 · 2 comments

Comments

@SrTobi
Copy link
Contributor

SrTobi commented Jan 2, 2025

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?)

@SrTobi SrTobi added the stat:needs triage Every issue needs to have an "area" and "itype" label label Jan 2, 2025
@Gedochao Gedochao added itype:question area:tooling area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 7, 2025
@Gedochao
Copy link
Contributor

Gedochao commented Jan 7, 2025

@EugeneFlesselle
Copy link
Contributor

Related to #21958 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants