Open
Description
trait A {
type T1
type T2
def foo[B <: T1 >: T2] = ... // is T2 <:< T1 in method?
}
As in order to call method foo
one needs to verify type bounds, it seems safe for me to assume T2 <:< T1
in the body of the method
This is needed for some compiler rewritings to be type-safe. Eg, specialization of a
class Foo[+A] {
def bop[@specialized B >: A]: Foo[B] = this
}
will yield
def bop_sp[@specialized B >: A <: Int & Any]: Foo[B] = this
Without typer knowing that Foo$A
is subtype of Int
in this example, specialization needs to insert casts.
Unfortunately, for the scheme to be complete, specialization needs to insert casts in every place where we have a source of expected type: arguments of methods, vals, defs. Otherwise the tree does not typecheck.
Metadata
Metadata
Assignees
Labels
No labels