review request for 8010225 test in typeAnnotations/failures do not test TYPE_USE
Steve Sides
steve.sides at oracle.com
Fri Oct 4 09:02:25 PDT 2013
Can these be put back as is or need more changes? They are simple fixes
to negative tests.
-steve
On 9/23/2013 11:49 AM, Steve Sides wrote:
> This makes the noted changes:
> http://cr.openjdk.java.net/~ssides/8010225.3/
>
> Also, I took out any changes to CantAnnotateStaticClass.java/out and
> this change leaves it as is. I saw Werner sent a much more
> comprehensive test for this as a mail attachement. It was
> CantAnnotateStaticClass2.java.
> Werner, could you put that test back as
> CantAnnotateStaticClass.java/.out since your test was inclusive of the
> first and that first was never completed (no final .out file)?
>
> -steve
>
> On 9/17/2013 12:29 PM, Alex Buckley wrote:
>> To all: there's a bug in case 4 below.
>>
>> On 9/17/2013 12:06 PM, Steve Sides wrote:
>>> 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.
>>
>> You are right. The annotation on the upper bound of T is illegal
>> because the Scopes.UniqueInner annotation type is applicable only in
>> locations which existed in Java SE 7 (such as type declarations) and
>> not in new locations in Java SE 8 (such as type uses).
>>
>>> 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
>>
>> The scope of the @interface declaration is the body of class Scopes.
>> Therefore, the simple name "UniqueInner" is not in scope before the {
>> of the declaration of Scopes. All three errors are correct.
>>
>>> 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.
>>
>> As it should.
>>
>>> 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?
>>
>> You are right to ponder what's going on. The third error, about
>> applicability, is a bug.
>>
>>> 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.
>>
>> Please add this test. The comment however should not mention
>> accessibility, which is a totally different concept. Say "The simple
>> name UniqueInner is not in scope on the header of class Scopes, so
>> @UniqueInner is not meaningful there. One must use the qualified
>> name, as in @Scopes.UniqueInner."
>>
>> In addition, the type parameter T is also out of UniqueInner's scope.
>> To ensure that annotations on the class declaration and annotations
>> on the type parameter declaration are handled consistently,
>> @UniqueInner should be written on T as well.
>>
>> Alex
>
More information about the type-annotations-dev
mailing list