-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Opaque type's type parameter widened causing implicit lookup failure #12950
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
For comparison, here is an example that is very similar to the above, just without using object repro2:
abstract class Lift[T]:
val value: Int
extension(v: Int)
def lift[T]: Lift[T] =
new Lift[T]:
val value = v
final type Two
extension[TL](l: Lift[TL])
def repro[TR](using m: Mul[TL, TR]): Int = l.value + m.value
abstract class Mul[TL, TR]:
val value: Int
transparent inline given mulGivenInt[TL <: Int & Singleton, TR <: Int & Singleton]: Mul[TL, TR] =
val m: Int = scala.compiletime.constValue[TL] * scala.compiletime.constValue[TR]
new Mul[TL, TR] { val value: Int = m }
transparent inline given mulGivenTwo[TR <: Int & Singleton]: Mul[Two, TR] =
val m: Int = 2 * scala.compiletime.constValue[TR]
new Mul[Two, TR] { val value: Int = m } In this example the integer literal is not widened and both invocations work: scala> import repro.repro2.{*, given}
scala> val x = 1.lift[Two]
val x: repro.repro2.Lift[repro.repro2.Two] = repro.repro2$$anon$1@386e9fd8
scala> x.repro[2]
val res0: Int = 5
scala> val y = 1.lift[2]
val y: repro.repro2.Lift[2] = repro.repro2$$anon$1@5b5b8730
scala> y.repro[2]
val res1: Int = 5 |
@anatoliykmetyuk I simplified it somewhat by removing the metaprogramming. I do not believe it can be further simplified and still show what I am trying to show. |
Int
for reference, the actual use case where this comes up is here: The type parameter |
I won't be able to work on the inliner for the time being. @nicolasstucki is already overloaded. We need some relief from others to step up here. |
Minimised to: Lib.scala opaque type F[T] = Int Main.scala type G[T]
given gt[T <: Int & Singleton]: G[T] = ???
def h[T](l: F[T])(using m: G[T]) = ???
val y = h(??? : F[2]) Compile separately. Output: -- Error: /Users/kmetiuk/Projects/scala3/playground/i12950/Bad/Main.scala:4:21 -
4 |val y = h(??? : F[2])
| ^
|no implicit argument of type G[Int] was found for parameter m of method h.
|I found:
|
| gt[T]
|
|But given instance gt does not match type G[Int]. If compiled together, the error goes away. |
Possibly related to #12945 |
Compiler version
3.0.0
Minimized code
Output
Expectation
In the second example
val y = 1.lift[2]
I would expect that the integer literal type parameter not be widened toInt
in the call toy.repro[2]
- it should succeed and return5
, the same as withx.repro[2]
Instead the
TL
type parameter is being widened toInt
:repro.repro.Mul[Int, (2 : Int)]
It seems to be specifically related to using
opaque type
- a more simple repro I attempted worked correctly, when the opaque type was not involved.The text was updated successfully, but these errors were encountered: