RFR: addressing several issues in the implementation of universal tvars [v9]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Jun 10 10:40:30 UTC 2022
On Wed, 8 Jun 2022 19:10:59 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> well `action`'s type is parameterized with a wildcard so here we are assigning a ref to a wildcard, `field = t` is not failing though that assignment generates a warning
>
> it could probably be better to write the test as:
>
> field = t;
> action.accept(field = t);
>
> what do you think?
Ah I see. So there's two things here:
1. assignment from `t` to `field` - that works ok (with warning)
2. passing `field` (of type `T.ref`) to `action`.
On (2), `action` is subject to capture conversion, so its type is `Consumer<#CAP>` where `T <: #CAP `. So, we have to check whether `T.ref` is assignable to `#CAP`. I believe this currently fails because `T.ref` cannot be "lifted" to `#CAP`.
I think this is ok for now, but I note that, when type variables are involved, there are always two ways to prove subtyping:
* T <: S iff upper(T) <: S
* S <: T iff S <: lower(T)
It is true that, in (2) you cannot "lift" `T.ref` to `'#CAP`, but it is also true that you can "unlift" `#CAP` down to `T`, at which point you would have a structural comparison between `T.ref` and `T` again (which would be ok).
Whether or not this is what we want to do is a specification question - we can revisit later. (Here I note that we don't currently do this even for ordinary unchecked conversions, so what we have is probably ok).
-------------
PR: https://git.openjdk.org/valhalla/pull/684
More information about the valhalla-dev
mailing list