RFR JDK14-8236597: issues inferring type annotations on records

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jan 10 19:23:53 UTC 2020

Looks good - but I have a question - I assume the changes in TypeEnter 
are to 'copy' the tree for the return type 'as is' from the record 
component declaration to the accessor return type. That is, is one is a 
qualified name, the other should be too, and viceversa.

Ok, my question then is: shouldn't something like this be said somewhere 
in the spec too? After all, since @Nullable foo.bar.Baz is invalid but 
@Nullable Baz is not (or should use generate code for foo.bar. at Nullable 
Baz ?)

And... what about parameter types? Shouldn't they need same treatment too?


On 10/01/2020 00:34, Vicente Romero wrote:
> Hi,
> Please review this patch [1] to fix a couple of issues regarding 
> inference of type annotations on records [2]. There where two cases 
> where type annotations were reported as missing. For compact records 
> whose arguments are not inheriting the type annotations from the 
> corresponding record component and for accessors for which the 
> annotation was present but just as a declaration annotation applied to 
> the accessor. Not as a type annotation applied to the return type 
> which was the expected outcome.
> In the case of the compact constructor, the solution was just to copy 
> the annotations to the parameters which were missing. In the case of 
> the accessor the solution was a bit more complicated. Accessors are 
> created but not added to the list definitions belonging to the record 
> tree. This is done to make them invisible to type attribution as they 
> are not fully fledge methods, but as a side effect they are also 
> invisible to the type annotations machinery. For this reason type 
> annotations were not recognized as such. The solution here has been to 
> make the type annotations machinery to visit accessors for records and 
> set the type annotations correctly. In order to do that the accessor 
> method created at TypeEnter is stored at the record component and 
> visited at the same time type annotations are being classified for the 
> rest of the code.
> Thanks,
> Vicente
> [1] http://cr.openjdk.java.net/~vromero/8236597/webrev.00/
> [2] https://bugs.openjdk.java.net/browse/JDK-8236597

More information about the compiler-dev mailing list