Integrated: 8288130: compiler error with AP and explicit record accessor
Vicente Romero
vromero at openjdk.org
Fri Jun 24 21:45:58 UTC 2022
On Wed, 15 Jun 2022 00:01:37 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> Please review this PR which is fixing a tricky bug in records. Right now this code is trivial to compile by javac:
>
> record TestRecord<T>(T someValue) {
> public T someValue() {
> return this.someValue;
> }
> }
>
> but in the presence of an annotation processor this code is entered at least two times. Every one of those times a new type variable is created. Now for records this have some implications. Record components are created once, in most cases unless there is an error for example, meaning that the type of the record component in this case was not in sync with the type of the accessor, and this is a mismatch reported as an error by the compiler. Note that if the accessor was not explicitly declared but generated this wouldn't happen as the accessor is generated from the info in the record component so a generated accessor is always in sync with its corresponding record component.
>
> A possible solution to this issue could be to recreate the record component if there is at least a type variable in its type. But I decided to go for an all in solution recreating the record component always so if there are annotation processor rounds, a new record component would be created for each of them. This way we can future-proof this area of records which has seen bugs in the past and be sure that we are always dealing with a fresh instance of the record components.
>
> TIA
This pull request has now been integrated.
Changeset: 53b37fe1
Author: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/53b37fe1535388eb14e04c620a6b0118ed8884a0
Stats: 308 lines in 5 files changed: 124 ins; 79 del; 105 mod
8288130: compiler error with AP and explicit record accessor
Reviewed-by: jlahoda
-------------
PR: https://git.openjdk.org/jdk/pull/9160
More information about the compiler-dev
mailing list