Skip to content

Preventing double definition for anonymous givens #18034

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

Closed
soronpo opened this issue Jun 21, 2023 · 2 comments
Closed

Preventing double definition for anonymous givens #18034

soronpo opened this issue Jun 21, 2023 · 2 comments

Comments

@soronpo
Copy link
Contributor

soronpo commented Jun 21, 2023

I'm not clear if this is indeed a bug, or a limitation that can be lifted with or without a SIP.

Compiler version

v3.3.0

Minimized code

https://scastie.scala-lang.org/7m7S5DcCQYeZioWaeM2Uqw

object One:
  trait Config

object Two:
  trait Config

given One.Config = ???
given Two.Config = ???

Output

Double definition:
final lazy given val given_Config: Playground.One.Config in object Playground at line 9 and
final lazy given val given_Config: Playground.Two.Config in object Playground at line 10

Expectation

I expect that the compiler will notice that both givens come from different paths and use them as a full name to prevent the double definition from occurring. So the compiler should desugar to:

final lazy given val given_One_Config = ???
final lazy given val given_Two_Config = ???
@soronpo soronpo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 21, 2023
@soronpo soronpo changed the title Preventing double definition for Preventing double definition for anonymous givens Jun 21, 2023
@sjrd
Copy link
Member

sjrd commented Jun 21, 2023

You can give them explicit names in user space. That's the disambiguation mechanism that is offered.

If the compiler did something automatic, the name would not be stable across two versions of a library where the second version adds the second definition. That would be very bad.

@soronpo
Copy link
Contributor Author

soronpo commented Jun 21, 2023

You can give them explicit names in user space.

Yeah, I'm aware.

If the compiler did something automatic, the name would not be stable across two versions of a library where the second version adds the second definition. That would be very bad.

That's right, I haven't considered that. We could avoid that by always using the suggested desugaring for given X.Y.Z, but this will break backward compatibility.

@soronpo soronpo closed this as completed Jun 21, 2023
@sjrd sjrd closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2023
@sjrd sjrd added itype:enhancement stat:wontfix and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 22, 2023
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

2 participants