-
Notifications
You must be signed in to change notification settings - Fork 21
Implicit conversion never applied but influences type inference #12044
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
Comments
Curious whether Dotty is different here. |
It works in Dotty 0.24.0-RC1:
|
Just Inferring |
To explain a bit - just testing implicit conversions accumulated type constraints. |
Dotty progressed. I think there is a ticket to improve scala-cli compile --server=false -S 3 t12044.scala
-- [E007] Type Mismatch Error: /home/amarki/snips/t12044.scala:11:6 ------------
11 | f(new Bar)
| ^^^^^^^
|Found: Bar
|Required: F[A]
|
|where: A is a type variable
| F is a type variable with constraint <: [_] =>> Any
|
|Note that implicit conversions were not tried because the result of an implicit conversion
|must be more specific than F[A]
|
| longer explanation available when compiling with `-explain`
[[syntax trees at end of typer]] // /home/amarki/snips/t12044.scala
package <empty> {
import language.implicitConversions
class Bar() extends Object() {}
final lazy module val Test: Test = new Test()
final module class Test() extends Object(), App { this: Test.type =>
def f[F[_ >: Nothing <: Any] >: Nothing <: Any, A >: Nothing <: Any](v: F[A]
): F[A] = v
implicit def barToList(b: Bar): List[Int] = List.apply[Int]([42 : Int]*)
Console.println(
{
Test.f[[_] =>> Any, Any](new Bar())
}
)
}
}
1 error found
Compilation failed With scala-cli compile --server=false -S 2 t12044.scala
/home/amarki/snips/t12044.scala:11: error: type mismatch;
found : Bar
required: List[A]
f(new Bar)
^
[[syntax trees at end of typer]] // t12044.scala
package <empty> {
import scala.language.implicitConversions;
class Bar extends scala.AnyRef {
def <init>(): Bar = {
Bar.super.<init>();
()
}
};
object Test extends AnyRef with App {
def <init>(): Test.type = {
Test.super.<init>();
()
};
def f[F[_] >: [_]Nothing <: [_]Any, A](v: F[A]): F[A] = v;
implicit def barToList(b: Bar): List[Int] = scala.`package`.List.apply[Int](42);
scala.Console.println(f(new Bar()))
}
}
1 error
Compilation failed |
reproduction steps
https://stackoverflow.com/questions/62415172/mere-presence-of-implicit-conversion-makes-the-program-compile-despite-never-bei/62426914
using Scala 2.13.2,
problem
I would expect implicit conversion would result in
where the following is inferred
instead of actual
Examining the output of
-Xprint:typer
shows the following implicit conversion never happendThe text was updated successfully, but these errors were encountered: