Hi Tagir,

Returning to this one:

> On 22 Jan 2020, at 08:03, Tagir Valeev <amae...@gmail.com> wrote:
> 
> Hello!
> 
> It appears that it's possible to annotate record component as
> @Override or @SafeVarargs, and spec doesn't explicitly forbid this:
> 
> record Test(@SafeVarargs int x, @Override int y) {}
> 
> In these cases, it's assumed that the annotation propagates to the
> accessor method. However, having @SafeVarargs on the accessor method
> is prohibited, so should be in a record component. So I expect to see
> in 9.6.4.7 something like this:
> 
>> It is a compile-time error if a record component (§8.10.1) is annotated with 
>> the annotation @SafeVarargs.
> 
> Having the @Override is possible on the accessor if accessor overrides
> the interface method (and it's really cool possibility!) Probably it's
> ok to allow this annotation on the record component in this case, but
> it should be definitely disallowed if the accessor doesn't override
> anything. So I expect something like this in 9.6.4.4:
> 
>> If a record component (§8.10.1) of record R is annotated with the annotation 
>> @Override and the accessor method for that component (§8.10.3) does not 
>> override a method declared in a superinterface of R (§8.4.8.1), then a 
>> compile-time error occurs.

I’d like to make sure both of these are covered as erroneous, but I’m not so 
keen on the suggested JLS text. Both of these cases are actually the same, i.e. 
the annotation on the implicitly declared method doesn’t make sense. So, I’d 
prefer to call that out explicitly as a single, catch-all rule. More precisely, 
in the draft spec in §8.10.3 on implicitly declared accessor methods is the 
following bullet-point:

- It is annotated with the annotations, if any, that appear on the corresponding
  record component and whose annotation types are applicable in the method
  declaration context, or in type contexts, or both.

I propose to amend this to the following:

- It is annotated with the annotations, if any, that appear on the corresponding
  record component and whose annotation types are applicable in the method
  declaration context, or in type contexts, or both. **The rules for these
  annotation modifiers, if any, on the accessor method are the same as for a
  method declaration, and are specified in [9.7.4] and [9.7.5].**

The last sentence is new, and mirrors what is said about normal method 
declarations in §8.4.3.

What do you think?
Gavin

Reply via email to