-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type mismatch error involving type member #3058
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
It seems that the refinement is not taken into account for type inference, but since there are so many different difficulties at play (generics, refinements, dependent methods) it's hard to tell. I don't think I have the time to track this down. If someone else wants to give it a go, please re-open. |
I recently went back to this and tried with the current version of Dotty. The bug still remains. However, I was able to simply the code a bit further: trait C { type U }
trait B[T]
def a: C { type U = Int } = ???
def b(c: C): B[c.U] = ???
def test[T](c: B[T]) = ???
test(b(a)) This code yields the error message:
I'm aware that the code uses some of the more advanced Scala features, but nothing really experimental. So my understanding is that they are supposed to be supported by Dotty. Especially for the simplified example, I think it's pretty obvious that the code should compile. Maybe we could leave the issue open to keep track of this bug? Further, in case the argument |
But I've taken a look at the new example and it's very non-obvious that it should compile, because you're trying to use type members of a I first suspected this would involve modifying
trait C { type U }
trait B[T]
def a: C { type U = Int } = ???
def b(c: C): B[c.U] = ???
def test[T](c: B[T]) = ???
// test(b(a))
//def res1 = test[a.U](b(a)) // fails
def res2 = test[(C { type U = Int})#U](b(a))
def res3 = test[Int](b(a)) |
Thanks for the detailed comments!
That clarifies the problem for me. Since
Just as a side note: Scalac also accepts the code when we leave
My mistake. I overlooked
Note that also making
Right, I also expected that the compiler is able to dealias |
I expect that falls under "Scala 2 unsoundness bugs fixed in Scala 3", see the blog posts for discussion (https://www.scala-lang.org/blog/2016/02/17/scaling-dot-soundness.html,
"Does not work" is too generic — "inference doesn't work, but a type argument does" is better. trait C { type U }
trait B[T]
val a: C { type U = Int } = new C { type U = Int }
// final def a: C { type U = Int } = ???
def b(c: C): B[c.U] = ???
def test[T](c: B[T]) = ???
def res0 = test(b(a)) // only this fails, the rest succeeds.
def res1 = test[a.U](b(a))
def res2 = test[(C { type U = Int})#U](b(a))
def res3 = test[Int](b(a)) On one thing I wrote:
Just realized: Conceivably, Dotty could represent the type of |
Closes lampepfl#3058 Closes lampepfl#10943 Closes lampepfl#12216 Closes lampepfl#12655
When compiling the following code:
Dotty produces the following compiler error:
There should be no type mismatch. Splitting the last expression like
val x = b(a); test(x)
works.The text was updated successfully, but these errors were encountered: