target_info structure of a method receiver
Alex Buckley
alex.buckley at oracle.com
Fri Sep 12 18:56:19 UTC 2014
I know what you mean, but there is no problem with javac here.
The only way to explain this precisely is to use a JLS concept. Per JLS8
4.11, a receiver parameter induces one type context - think of it as the
area in Foo's ctor signature after '(' and before 'Receiver.this'. It is
this type context of which there is "only one". There may be many types
"inside" the type context if a nested, array, or parameterized type is
involved, and the target_path structure will take care of getting you to
a particular one - but there's only one area.
Same deal with the type context for a field declaration - you already
know the field (the attribute is within a field_info) so there is only
one area where the type of the field can be written. Contrast with a
formal parameter declaration - the attribute is inside a method_info so
there needs to be a way to identify a particular formal parameter
(formal_parameter_target) which provides the area (type context) where
the type of the formal parameter can be written.
I'm not sure it's worth rewriting the informative JVMS text. The
normative text for empty_target already mentions "_the_ type in a field
declaration" and "_the_ receiver type of a method or constructor", and
there are other mentions of "_the_ type" throughout 4.7.20.1. Appealing
to "the type context" rather than "the type" seems more trouble than
it's worth.
Alex
On 9/12/2014 7:58 AM, Joel Borggren-Franck wrote:
> Hi,
>
> The table 4.7.20-A and section 4.7.20.1 in JVMS says that a method
> receiver target kind is followed by the empty_target target info, noting
> that "Only one type appears in each of these locations, so there is no
> per-type information to represent in the target_info union.", yet the
> following program compiles with both 8 and 9 javac:
>
> --- 8< ---
>
> import java.lang.annotation.*;
> import java.lang.reflect.*;
>
> public class Receiver<T, U> {
>
> @Target(ElementType.TYPE_USE)
> @Retention(RetentionPolicy.RUNTIME)
> @interface A {
> }
>
> class Foo {
> Foo(@A Receiver<@A T, @A U> Receiver.this) {
> }
> }
>
> public void m(@A Receiver<@A T, @A U> this, int j) { ; }
> }
>
> --- 8< ---
>
> Isn't this 3 type uses in both the ctor and the method?
>
> I haven't found anything in JLS to indicate if javac or JVMLS is wrong
> here.
>
> cheers
> /Joel
>
More information about the compiler-dev
mailing list