Skip to content

Infix types doesn't work correctly with anonymous givens #10927

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
ghost opened this issue Dec 27, 2020 · 4 comments · Fixed by #11838
Closed

Infix types doesn't work correctly with anonymous givens #10927

ghost opened this issue Dec 27, 2020 · 4 comments · Fixed by #11838
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Dec 27, 2020

infix types fails with Double definition compile error while using with givens.

  trait Transition[From, To]

  infix type ==>[From, To] = Transition[From, To]

  type A = A.type
  object A

  type B = B.type
  object B

  type C = C.type
  object C

  // Compiles
  given (A ==> B) = ???

  // Compile error
  given (A ==> C) = ???

  // Compiles
  given ==>[A, C] = ??? 

Error:

Double definition:
final lazy given val given_A: 
  Transition[A, B] in object bug at line 19 and
final lazy given val given_A: 
  Transition[A, C] in object bug at line 22

  given (A ==> C) = ???
@ghost ghost added the itype:bug label Dec 27, 2020
@odersky
Copy link
Contributor

odersky commented Dec 27, 2020

That's as specified. You need to give explicit names to the givens.

@odersky odersky closed this as completed Dec 27, 2020
@som-snytt
Copy link
Contributor

It is specified that explicit names may be required.

But it is probably an oversight that the synthesized name for the value of infix type is different from the normal form.

It means given infix clashes with simple given of the argument:

given A = ???    // given_A
given (A Tuple2 B) = ???  // given_A
given (A, B) = ???    // given_A_B

https://dotty.epfl.ch/docs/reference/contextual/givens.html
https://dotty.epfl.ch/docs/reference/contextual/relationship-implicits.html#anonymous-given-instances

    final lazy given val given_A: X.==>[X.A, X.B] = ???
    final lazy given val given_A: X.==>[X.A, X.C] = ???
    final lazy given val given_==>_A_C: X.==>[X.A, X.C] = ???

@smarter
Copy link
Member

smarter commented Dec 27, 2020

I think that's reasonable, it sounds like the status quo makes anonymous given basically unusable for infix types, and that should be easily fixable by adding a case for InfixOp in https://github.com/lampepfl/dotty/blob/8fab91c1ae8237d4ceffce611fff059d969c4ae4/compiler/src/dotty/tools/dotc/ast/Desugar.scala#L950-L962 if I'm not mistaken, but this will need to be done before 3.0 or not at all.

@smarter smarter reopened this Dec 27, 2020
@smarter smarter added this to the 3.0.0-RC1 milestone Dec 27, 2020
@odersky
Copy link
Contributor

odersky commented Dec 28, 2020

OK, I agree that the case should be added

@anatoliykmetyuk anatoliykmetyuk modified the milestones: 3.0.0-RC1, 3.0.0-RC2 Feb 11, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 22, 2021
@odersky odersky assigned odersky and unassigned smarter Mar 22, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 22, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 22, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 22, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 14, 2021
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants