[type-annos-observers] Constraining type annotations to occur just before type
Michael Ernst
mernst at cs.washington.edu
Mon Apr 8 20:42:00 PDT 2013
Srikanth-
Thanks for the continued comments. This discussion is useful.
I agree that arrays are an interesting and potentially tricky special case,
because Java puts the main part of an array type last instead of first.
But, I would caution against basing an argument too strongly on array
examples. Most Java code does not use arrays, or at least uses them less
than non-arrays. I am reluctant to break source-code compatibility (that
is, force refactoring and possibly prevent old and new tools from being run
on a single codebase) in the common case in order to give a compile-time
warning for the uncommon case. That's especially true because running a
pluggable type-checker would already provide the programmer with
compile-time warnings about any annotations that are being interpreted
differently than the programmer intended.
Adding TYPE_USE to @Target purely augments the behavior and never actually
changes it in an incompatible way. I think a misunderstanding of this
might be at the root of some of our disagreements. (By contrast, your
incompatibility argument is valid if one were to change a declaration
annotation, so that it is no longer applicable at declaration locations.
But that isn't the use case you were thinking of, I believe.)
The JLS grammar might be another source of confusion. There is just one
production for all annotations, and it might seem that thus all those
annotations belong to the declaration. That is not the case -- in the
language model, some annotations belong to the type and some belong to the
declaration, regardless of the parsed AST produced by the JLS grammar.
-Mike
More information about the type-annotations-spec-observers
mailing list