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
wrong lub of types involving f-bounded polymorphism #2251
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2251?orig=1 |
@adriaanm said: |
@odersky said: The current way to treat F-bounds is to ignore them totally when forming lubs and when doing type inference, and then checking after the fact that inferred types satisy the bounds. How did bug1001 fail? I think we need to dig a bit deeper here. |
@adriaanm said: Compiler output (edited to remove irrelevant stuff -- with printLubs enabled and some diagnostics in mergePrefixAndArgs): lub of List(D, C) at depth 2
lub of List(D, C) at depth 1
lub of List(D, C) at depth 0
lub of List(D, C) is A
MPAA of: List(B[D], B[C])
MPAA(params, sym, args) = (List(type _1 >: D with C <: A),trait B,List(_1))
lub of List(D, C) is B[_ >: D with C <: A]
MPAA of: List(B[D], B[C])
MPAA(params, sym, args) = (List(type _2 >: D with C <: B[_ >: D with C <: A]),trait B,List(_2))
lub of List(D, C) is B[_ >: D with C <: B[_ >: D with C <: A]]
/Users/adriaan/git/scala/test/files/pos/ticket2251.scala:22: error: type arguments [_1] do not conform to trait B's type parameter bounds [T <: B[T]]
val data: List[A] = List(new C, new D)
^
one error found Maybe this is the expected behaviour then? Should we focus on providing a better error message and leave mergePrefixAndArgs as it was? Anyway, the inferred type is:
instead of the well-formed:
it's interesting that this first type is the unrolling (up to a certain depth) of the second one -- there's probably no complete algorithm to detect this and "roll the type back up", though... (is there?) I'm not sure whether this could work, but maybe we could improve mergePrefixAndArgs so that it detects f-bounds (with a more robust check) and then takes the type schema and replaces the type parameters by existentials? E.g., |
@paulp said: class A
trait B[T <: B[T]] extends A
class C extends B[C]
class D extends B[D]
class E {
val ys = List(List(new C), Stream(new D))
} If you compile with -Ydebug you can watch the malformed lubs as they are discarded. Eventually it admits defeat:
|
@paulp said: |
@adriaanm said: |
@adriaanm said: |
after fixing SI-513, pos/bug1001 failed -- it turns out there was another bug hiding under SI-513's shroud
This test case is derived from pos/bug1001, and may also be related to #1159
output with printLubs enabled:
clearly,
_2
inB[_2] forSome { type _2 >: D with C{} <: B[_1] forSome { type _1 >: D with C{} <: A } }
is not a subtype ofB[_2]
I don't know how to fix this more constructively but to detect f-bounded type params in
mergePrefixAndArgs
and pretenddepth == 0
:The text was updated successfully, but these errors were encountered: