RFR: bug: no warning shown for parameterized conversions [v4]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Mar 9 14:30:27 UTC 2022
On Wed, 9 Mar 2022 14:12:28 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java line 2034:
>>
>>> 2032:
>>> 2033: public Type withTypeVar(Type t) {
>>> 2034: return t.hasTag(TYPEVAR) && t.isReferenceProjection() && t == projection ?
>>
>> Uhm - this method is typically used to set type-variables on wildcard types. It is a bit of a corner case in the compiler code, and I think it would be better to leave this alone. What is this code trying to do - and can the same be achieved in another way?
>
> this code is preserving the reference projection of a type var, if it was originally declared as a reference `T.ref`, instead of overriding it with its dual `T`. If the reference projection is not preserved then it leads to information loss. I haven't found another more reliable way
I guess what I'm saying is that this method is designed to cause side-effects on the type it's called on. I believe that this method was originally only used in `Attr.visitTypeApply`, so that if you have a declaration like:
class Box<X> { ... }
And a type use like:
Box<? extends String>
When we hit `Attr.visitTypeApply`, we set the `bound` field of the `WildcardType` for `? extends String` to point to `X`. This field is then used in type containment tests.
The whole logic is dubious, and predates my time - but I have a feeling that depending on this obscure method to get the desired behavior is not correct.
-------------
PR: https://git.openjdk.java.net/valhalla/pull/666
More information about the valhalla-dev
mailing list