[type-annos-observers] error: enclosing static nested class cannot be annotated ??

Werner Dietl wdietl at gmail.com
Mon Oct 7 20:27:41 PDT 2013


Hi Srikanth,

thanks for the additional test cases!

On 10/07/2013 11:12 PM, Srikanth S Adayapalam wrote:
> I'll let this discussion take its course to see where it leads. In the
> meantime here are
> some other examples that show the reference compiler (8b108) behaving
> inconsistently.
> This is admittedly not the place to report RI issues, but to the extent
> they are pertinent
> to the discussion at hand, they should be useful:
> Thanks,
> Srikanth
> 
> 1.  I would expect two errors here, but get only one:
> 
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Target;
> 
> @Target(ElementType.TYPE_USE)
> @interface Illegal {
> }
> class Y {
>                 static class Z {
>                                  Z() {}
>                 }
> }
> class X {
>                 Y.Z foo() {
>                                  @Illegal Y.Z z = null;
>                                  return z;
>                 }
>                 Y.Z bar() {
>                                  Y.Z z = (@Illegal Y.Z)null;   // No
> error here ??
>                                  return z;
>                 }
> }


This is fixed in the type-annotations version. I get two errors:

Srikanth1.java:14: error: scoping construct cannot be annotated with
type-use annotation: @Illegal
                                 @Illegal Y.Z z = null;
                                           ^
Srikanth1.java:18: error: scoping construct cannot be annotated with
type-use annotation: @Illegal
                                 Y.Z z = (@Illegal Y.Z)null;   // No
error here ??
                                                   ^
2 errors


> 2. I would not expect an error at annotation site of @LegalTypeUseParam:
> I would expect
> that the TYPE_USE target to be silently discarded and the PARAMETER
> target to be honored.
> This is by intuition, not sure if the spec sanctions such.
> 
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Target;
> 
> @Target(ElementType.TYPE_USE)
> @interface IllegalTypeUse {
> }
> @Target({ElementType.TYPE_USE, ElementType.PARAMETER})
> @interface LegalTypeUseParam {
> }
> @Target(ElementType.PARAMETER)
> @interface LegalParam {
> }
> class Y {
>                 static class Z {
>                                  Z() {}
>                 }
> }
> class X {
>                 Y.Z foo(@LegalParam Y.Z z) { //Legal
>                                  return z;
>                 }
>                 Y.Z foo2(@LegalTypeUseParam Y.Z z) { //Legal
>                                  return z;
>                 }
>                 Y.Z foo3(@IllegalTypeUse @LegalParam Y.Z z) { //Illegal
>                                  return z;
>                 }
> }

With the type-annotations version I get one error:

Srikanth2.java:25: error: scoping construct cannot be annotated with
type-use annotation: @IllegalTypeUse
                Y.Z foo3(@IllegalTypeUse @LegalParam Y.Z z) { //Illegal
                                                      ^
1 error


I hope this updated behavior is what you expect.

cu, WMD.


More information about the type-annotations-spec-observers mailing list