I’m running in to an interesting issue with generi...
# announcements
d
I’m running in to an interesting issue with generics and nested classes. For some reason changing the type parameter’s variance to in/out from invariant changes the visibility of a property using that type parameter.
To clarify, the actual compilation error is happening on line 8 in the example code
f.something = {}
does anyone have an explanation for why things work this way?
c
that's pretty weird. guessing something to do with erasure
can you try specifying the type of the lambda? like
val l: (String) -> Unit = {}
and then setting f.something equal to that?
d
That doesn’t solve the problem unfortunately. I think it’s either 1) a compiler bug (unlikely) or 2) deliberate limitation on the compiler’s end because it’s potentially unsafe the compiler can’t prove that it’s safe. 3) there’s some case that I’m not thinking of where doing assignment from a nested class can break co/contra-variance.
It’s worth noting that it’s an access related error message and not a generics / type inference error message.
i
Strange indeed