LVTI: as per spec upward projection couldn't have resulted in a '? extends' parameterization
Dan Smith
daniel.smith at oracle.com
Wed Oct 11 20:39:54 UTC 2017
Hey, thanks for careful testing of these rules. I'm sure they can use some scrutiny!
> On Oct 11, 2017, at 9:57 AM, Georgiy Rakov <georgiy.rakov at oracle.com> wrote:
>
> 4. Afterwards following assertion from [1] is touched:
> If U is not Object, and if either the declared bound of the ith parameter of G, Bi, mentions a type parameter of G, or Bi is not a subtype of U, then Ai' is an upper-bounded wildcard, ? extends U.
> Here we have just B1 which is C1, so:
> a. "U is not Object" is true since U is C1;
> b. "the declared bound of the ith parameter of G, Bi, mentions a type parameter of G" is false since B1 is C1 - no type parameters are mentioned;
> c. "Bi is not a subtype of U" is false because both B1 and U are C1 so B1 is a subtype of U since a class is always a subtype of itself.
>
> For this reason A1' cannot be defined by this assertion as ? extends C1 which would make upward projection to result in Shell<? extends C1>, so none of other assertions can do either.
You are right that this rule does not apply.
What you are missing is that, per the subsequent rules, the type is
Shell<?>
Subsequently, all reads of 'z' have type
capture(Shell<?>) = Shell<CAP> where CAP extends C1
In other words, there is no need to mention C1 in the type, because it is implicit from the declaration-site bound of T in Shell.
> It's not quite clear why "Bi is not a subtype of U" was added to the specification. Some examples clarifying this point would be highly appreciated.
Ideally, we'd like an upper bound and a lower bound:
? extends upward(Ai) super downward(Ai)
However, wildcards aren't expressive enough to have both upper and lower bounds, so we have to pick one. The heuristic is: if the upper bound is "meaningful", use that. If the upper bound is not meaningful, use the lower bound instead (or nothing, if there is no lower bound). The definition of "meaningful" is, loosely, "something that may affect the upper bound of the capture of the result".
If Bi is a subtype of of U, then U will not affect the upper bound of the capture of the result, because capture will just do a glb(Bi, U) = Bi.
—Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20171011/cc417f17/attachment.html>
More information about the compiler-dev
mailing list