Skip to content

Generated given instances' names are the same for different types #15316

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
nikololiahim opened this issue May 29, 2022 · 3 comments
Closed

Generated given instances' names are the same for different types #15316

nikololiahim opened this issue May 29, 2022 · 3 comments
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@nikololiahim
Copy link

nikololiahim commented May 29, 2022

Compiler version

3.1.2

Minimized code

//> using scala "3.1.2"

trait Thing[A]
trait Box[A]

given Thing[Box[Int]] = new Thing[Box[Int]] {}
given Thing[Box[String]] = new Thing[Box[String]] {}

Output

Double definition:
final lazy given val given_Thing_Box: Thing[Box[Int]] in package object bug$package at line 6 and
final lazy given val given_Thing_Box: Thing[Box[String]] in package object bug$package at line 7
bloop

Expectation

The code should compile and the instances of Thing for both Box[String] and Box[Int] should be available.

@nikololiahim nikololiahim added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 29, 2022
@som-snytt
Copy link
Contributor

It specifies "top-level argument type constructors" at https://dotty.epfl.ch/docs/reference/contextual/relationship-implicits.html#anonymous-given-instances

which is linked from https://dotty.epfl.ch/docs/reference/contextual/givens.html#anonymous-givens

where it says the generated names are not conflict-free.

The only problem in computer science harder than naming is automatic name generation.

@bishabosha
Copy link
Member

bishabosha commented May 30, 2022

as mentioned above, this problem is documented and as specified, so I will close.

I'm not sure of your original code but could something like the following work?

given [T](using Box[T]): Thing[Box[T]] = ...

you can also use a type alias:

type BoxInt = Box[Int]
type BoxString = Box[String]
given Thing[BoxInt] = new Thing[BoxInt] {}
given Thing[BoxString] = new Thing[BoxString] {}

@nikololiahim
Copy link
Author

@bishabosha @som-snytt The workarounds do work. Thank you for the pointers to docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

3 participants