Vampire
06/05/2020, 6:38 PMopen class A
interface B
class AB: A(), B
class CD: A(), B
fun <T> foo(t: T): Nothing? where T : A, T : B = null
val a = foo(AB())
val b = listOf(AB()).map(::foo)
val c = listOf(AB(), CD()).map(::foo)
The last one with c
is not compiling.
Does anyone have an idea how to make the last line also work?
It gives the compilation error
Type parameter bound for T in fun <T : A> foo(t: T): Nothing? where T : B is not satisfied: inferred type Any is not a subtype of ASo it seems while the created list could be of needed types
A
and B
, the type inference is not smart enough here but creates a List<Any>
Is there a way to fix this, e. g. to explicitly define the List type somehow?
Interestingly the type inference in IntelliJ is smart enough to handle it properly and does not show an error, only the compiler bails out.Kroppeb
06/06/2020, 10:17 AMList<{A & B}>
, something the old one couldn't do.
The compiler still uses the old inference for now but that can be changed with a compiler flagVampire
06/06/2020, 10:53 AMList<{A & B}>
and it was not valid syntax.Kroppeb
06/08/2020, 10:09 AMVampire
06/08/2020, 10:11 AMA
and throw exception if not is B
or the other way around until 1.4 is used :-(