review request for 8010225 test in typeAnnotations/failures do not test TYPE_USE
Alex Buckley
alex.buckley at oracle.com
Tue Sep 17 13:10:32 PDT 2013
There should be no applicability check if the annotation's name can't be
resolved. That's how it worked in SE 7 for the old targets:
@UniqueInner
class Scopes {
@Target(ElementType.FIELD) // Anything but TYPE
@interface UniqueInner {}
}
gives one error, about not finding the symbol UniqueInner in the annotation.
I notice that an annotation on a type parameter declaration is treated
like an annotation on a type use; the following code gives two errors
(can't resolve + not applicable) but should only give one.
class Scopes<@UniqueInner T> {
@interface UniqueInner {} // Not applicable to type parameter decls
}
Alex
On 9/17/2013 12:24 PM, Werner Dietl wrote:
> Hi Steve,
>
> thanks for testing these cases!
> In your last case:
>
> @UniqueInner
> class Scopes<T extends @UniqueInner Object> {
> @Target(ElementType.TYPE_USE)
> @interface UniqueInner { };
> }
>
> The compiler cannot resolve the annotation on the class declaration
> and on Object and we therefore get the first two errors.
> Because the compiler cannot resolve the annotation, it doesn't know
> that it has meta-annotation TYPE_USE. We therefore get the third
> error, because it sees an annotation in a type-use location without
> knowing that it has the right meta-annotation.
>
> Maybe the check for the TYPE_USE target should be ignored if the
> annotation can't be resolved?
> A declaration annotation is by default valid in all locations, so the
> issue doesn't arise for declaration annotations.
>
> Thoughts?
>
> cu, WMD.
>
>
> On Tue, Sep 17, 2013 at 12:06 PM, Steve Sides <steve.sides at oracle.com> wrote:
>> On 9/16/2013 5:20 PM, Alex Buckley wrote:
>>>
>>> On 9/16/2013 2:42 PM, Steve Sides wrote:
>>>>
>>>> On 9/13/2013 10:42 AM, Alex Buckley wrote:
>>>>>
>>>>> - AnnotationVersion: The @summary is imprecise - the test is about the
>>>>> receiver parameter 'this', not type annotations in general. In SE 6
>>>>> and 7 and 8, the annotation type 'A' with no
>>>>
>>>> I'm not so sure I agree with that. Due to the 3 @compile lines, the test
>>>> is about allowing type-annotations only with jdk8. The fact that he put
>>>> the annotation on 'this' appears to me to be incidental. It may be odd
>>>> that he chose 'this' as opposed to maybe 'String' or some other more
>>>> common usage, but it does seem to be just a usage to make the general
>>>> point and elicit the diagnostic
>>>> "compiler.err.type.annotations.not.supported.in.source: 1.7", and not to
>>>> test that specific usage.
>>>
>>>
>>> This test aims to show that "type annotations" didn't exist and now do
>>> exist. In other words, that an annotation was not permitted in some
>>> type-oriented location in 6/7 but is permitted in that location in 8. It is
>>> poor form to choose a location in 8 which didn't exist in 6/7 - especially
>>> when that location is frankly very obscure. I would suggest putting the @A
>>> on something simple like an 'extends' clause.
>>>
>>> In addition, ElementType.TYPE_USE didn't exist in 6/7 so a reader might
>>> ask why javac doesn't complain about that rather than the syntax error of
>>> the 'this' parameter. This is why I also suggested having a companion test
>>> where a ElementType from 6/7 was used.
>>>
>>> Alex
>>
>> Got it. While whittling on this, I have another question about the
>> compiler's behavior.
>> 1. If I qualify the (not type) annotation,
>>
>> @Scopes.UniqueInner
>> class Scopes<T extends @Scopes.UniqueInner Object> {
>> @interface UniqueInner { };
>> }
>> I get 1 error, "Scopes.java:11:24:
>> compiler.err.annotation.type.not.applicable". This seems correct as I'm
>> using an annotation on a type usage, and the one on the class is okay.
>>
>> 2. If I use the annotation unqualified, I get 3 errors, two for
>> "cant.resolve..." and the one above again. I can see that this can also be
>> correct.
>>
>> Scopes.java:10:2: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
>> // on the class
>> Scopes.java:11:25: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
>> // on the bound
>> Scopes.java:11:24: compiler.err.annotation.type.not.applicable
>> // not a type annotation(I assumed)?
>> 3 errors
>>
>> 3. If I use a qualified type annotation,
>> @Scopes.UniqueInner
>> class Scopes<T extends @Scopes.UniqueInner Object> {
>> @Target(ElementType.TYPE_USE)
>> @interface UniqueInner { };
>> }
>> it compiles without error.
>>
>> 4. However, if I use an unqualified type annotation,
>> @UniqueInner
>> class Scopes<T extends @UniqueInner Object> {
>> @Target(ElementType.TYPE_USE)
>> @interface UniqueInner { };
>> }
>> I get the same 3 errors as the unqualified annotation:
>>
>> Scopes.java:10:2: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
>> Scopes.java:11:25: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
>> Scopes.java:11:24: compiler.err.annotation.type.not.applicable
>> 3 errors
>>
>> Why should I get "compiler.err.annotation.type.not.applicable" in this last
>> scenario? For 1. I kind of assumed the third error meant it was not
>> applicable because it was not a type annotation. Is it not applicable for
>> reasons other than not being TYPE_USE?
>>
>> I'm thinking of using it as below (and adding a postivie version with
>> qualified name),
>>
>> @UniqueInner
>> class Scopes<T extends @UniqueInner Object> {
>> // Unqualified @UniqueInner is not accessible to the class .
>> // One has to use @Scopes.UniqueInner.
>> @Target(ElementType.TYPE_USE)
>> @interface UniqueInner { };
>> }
>>
>> but I'm unsure about that third error and would like to verify it is as
>> expected.
>>
>> -steve
>>
>>
>>
>>
>>
>>
>
>
>
More information about the type-annotations-dev
mailing list