Skip to content
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

Overload resolution with expected type prematurely discards matching alternative #10746

Open
szeiger opened this issue Feb 22, 2018 · 0 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should compile typer
Milestone

Comments

@szeiger
Copy link

szeiger commented Feb 22, 2018

In the following piece of code the call to f at the end relies on the implicit conversion arrToIt to convert the result of one of the arr calls to an It[T]. This results in an expected type of It[?] for selecting among the 3 arr methods. As can be seen from the error message the correct one is not even considered.

class Arr[T]

class It[T]

implicit def arrToIt[T](xs: Arr[T]): It[T] = new It[T]

def arr[T](x: T, y: T): Arr[T] = new Arr[T]
def arr(x: Int, y: Int): Arr[Int] = new Arr[Int]
def arr(x: Byte, y: Byte): Arr[Byte] = new Arr[Byte]

def f[T](ys: It[T]): Unit = ()

f(arr("", null))

This fails to compile with

error: overloaded method value arr with alternatives:
  (x: Byte,y: Byte)this.Arr[Byte] <and>
  (x: Int,y: Int)this.Arr[Int]
 cannot be applied to (String, Null)
f(arr("", null))
  ^

If the single arrtoIt is replaced by

implicit def refArrToIt[T <: AnyRef](xs: Arr[T]): It[T] = new It[T]
implicit def byteArrToIt(xs: Arr[Byte]): It[Byte] = new It[Byte]
implicit def intArrToIt(xs: Arr[Int]): It[Int] = new It[Int]

it compiles successfully.

The situation looks similar to other overload-related bugs like #10576 but is probably not the same because in this case the correct alternative is prematurely discarded, which does not seem to play a part in the other bugs.

Tested with Scala 2.12.2 and 2.13.0-M3

@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Jul 7, 2020
@SethTisue SethTisue added this to the Backlog milestone Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should compile typer
Projects
None yet
Development

No branches or pull requests

3 participants