Skip to content

Seemingly unrelated polymorphic function causes "ambiguous overload error" #16067

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

Open
hmf opened this issue Sep 19, 2022 · 0 comments
Open

Seemingly unrelated polymorphic function causes "ambiguous overload error" #16067

hmf opened this issue Sep 19, 2022 · 0 comments

Comments

@hmf
Copy link

hmf commented Sep 19, 2022

Compiler version

Tried this with 3.2.1-RC2 and 3.2.1-RC1.

Minimized code

import scala.annotation.targetName

enum CT:
  case LOCAL_DATE, LOCAL_DATE_TIME, INT

def cv[T](i: String) =
  s"cv('$i')"

@targetName("cv_date")  
def cv[T <: CT.LOCAL_DATE.type](i: Int) =
  s"cv[LocalDate]('$i')"

@targetName("cv_date_time")  
def cv[T <: CT.LOCAL_DATE_TIME.type](i: Int) =
  s"cv[LocalDateTime]('$i')"

cv[CT.LOCAL_DATE.type] (0)
cv[CT.LOCAL_DATE_TIME.type] (1)

Test may be found in scastie

Output

cv[CT.LOCAL_DATE.type] (0)
Ambiguous overload. The overloaded alternatives of method cv in object Playground with types
 [T <: (Playground.CT.LOCAL_DATE_TIME : Playground.CT)](i: Int): String
 [T <: (Playground.CT.LOCAL_DATE : Playground.CT)](i: Int): String
both match type arguments [(Playground.CT.LOCAL_DATE : Playground.CT)] and arguments ((0 : Int))

cv[CT.LOCAL_DATE_TIME.type] (1)
Ambiguous overload. The overloaded alternatives of method cv in object Playground with types
 [T <: (Playground.CT.LOCAL_DATE_TIME : Playground.CT)](i: Int): String
 [T <: (Playground.CT.LOCAL_DATE : Playground.CT)](i: Int): String
both match type arguments [(Playground.CT.LOCAL_DATE_TIME : Playground.CT)] and arguments ((1 : Int))

Expectation

I would expect the code above to compile. If I comment out the first "unrelated" function, it does compile. This also occurs for methods.

I have also noticed the following. If I use this as the 1st function instead:

def cv[T](i: Int) =
  s"cv('$i')"

The error messages also refer to it as a possible ambiguous overload. In this case, I still think it should compile.

@hmf hmf added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 19, 2022
@WojciechMazur WojciechMazur added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 19, 2022
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