spec clarification: type annotations on static nested types
Alex Buckley
alex.buckley at oracle.com
Mon Dec 10 22:56:51 UTC 2018
On 12/7/2018 3:32 PM, Liam Miller-Cushon wrote:
> I filed a specification/vm bug as suggested:
> https://bugs.openjdk.java.net/browse/JDK-8215035
Thanks.
A small comment on this part: "If the value of path_length is 0, and the
annotation appears on a nested type, the annotation applies to the
outermost enclosing type for which a type annotation is admissible."
It's possible to read this and say, "The outermost enclosing type OF
WHAT? Oh, it must mean the outermost enclosing type _of the nested type
on which the annotation appears_. But I don't know the nested type on
which the annotation appears -- that's what type_path is meant to tell me."
(See table 4.7.20.2-F proposed in JDK-8215035) That is, "nested type"
can mean "the nested type Outer.MiddleStatic.Inner on which @A appears
somewhere", as suggested by the formulation of "T1.T2" in the
introduction; or it can mean "the nested type Inner or the nested type
Inner2 or the nested type Inner3 which are all components of the nested
type Outer.MiddleStatic.Inner.Inner2.Inner3", and if you do that, then
path_length=0 could be referring non-deterministically to any of them in
order to point to the outermost enclosing admissible location (i.e.
MiddleStatic).
To avoid confusion, the rule should be: "If the value of path_length is
0, and the type being annotated is a nested type, then the annotation
applies to the outermost [DELETE]enclosing[/DELETE] part of the type for
which a type annotation is admissible." [I don't say "outermost
component" because component is used in connection with array types.]
There's a certain "top-down" feel to this, which is unavoidable because
a class file reader comes to type_path knowing the (say) parameter type
which is being annotated, and wishing to know which part of the type has
the annotation. 4.7.20.2 used to be like that -- "the top level type or
any member type" -- but got itself turned around -- "the innermost
member type and any enclosing ...".
Make sense?
> (I also fixed typos in JDK-8198526 with the static nested class example,
> and a reference to the wrong type_path_kind. Let me know if I missed
> anything.)
I made some small corrections, e.g. to avoid "enclosing instance type".
Alex
More information about the compiler-dev
mailing list