scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Using full qualifier names for anonymous given naming to avoid double definition #21406

Closed soronpo closed 1 month ago

soronpo commented 1 month ago

Compiler version

v3.5.0

Minimized code

object Bar:
  trait Foo

object Baz:
  trait Foo

given Bar.Foo = ???
given Baz.Foo = ???

Output

Double definition:
final lazy given val given_Foo: Playground.Bar.Foo in object Playground at line 9 and
final lazy given val given_Foo: Playground.Baz.Foo in object Playground at line 10

Expectation

Naming will be according to the full select name to resolve the double definition.

final lazy given val given_Bar_Foo: Playground.Bar.Foo = ???
final lazy given val given_Baz_Foo: Playground.Baz.Foo = ???

I'm unsure if binary compatibility is an issue here.

sjrd commented 1 month ago

Yes, binary and tasty and even source compatibility are issues.

No, we cannot ever change the naming of anonymous givens. It is what it is.

soronpo commented 1 month ago

Yes, binary and tasty and even source compatibility are issues.

No, we cannot ever change the naming of anonymous givens. It is what it is.

@sjrd What if we only do the following in case of a double definition conflict?:

final lazy val given_Foo: Playground.Bar.Foo = ???
final lazy given val given_Bar_Foo: Playground.Bar.Foo = given_Foo

That should preserve both source and binary compatibility.

sjrd commented 1 month ago

No, it won't. We don't know which one was added first and must be preserved. If they're separately compiled, we also don't know which one to rename.