-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a long-standing bug with type annotation paths on raw inner class…
… types As described in [JVMS 4.7.20.2](https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7.20.2), type annotations on nested types are located with `type_path_kind=1` type path entries, which describe steps starting with the 'outermost part of the type for which a type annotation is admissible'. Turbine represents class types for inner classes as a flat list of 'simple class types' corresponding to outer and inner classes. The 'canonicalization' step normalizes type arguments, and also ensures there's exactly one entry for each nested class and non-static containing class. The former doesn't apply to raw types (we erase the entire type if any part of it is raw), but the latter is important to ensure we compute the right number of type path steps for inner classes. PiperOrigin-RevId: 576191070
- Loading branch information
Showing
5 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
javatests/com/google/turbine/lower/testdata/type_anno_nested.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
=== Annotations.java === | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(TYPE_USE) @interface A {} | ||
@Target(TYPE_USE) @interface B {} | ||
@Target(TYPE_USE) @interface C {} | ||
|
||
=== Outer.java === | ||
class Outer { | ||
|
||
@A Outer . @B Middle . @C Inner f; | ||
Outer . @A MiddleStatic . @B Inner g; | ||
Outer . MiddleStatic . @A InnerStatic h; | ||
|
||
class Middle { | ||
class Inner {} | ||
} | ||
static class MiddleStatic { | ||
class Inner {} | ||
static class InnerStatic {} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
javatests/com/google/turbine/lower/testdata/type_anno_nested_generic.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
=== Annotations.java === | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(TYPE_USE) @interface A {} | ||
@Target(TYPE_USE) @interface B {} | ||
@Target(TYPE_USE) @interface C {} | ||
@Target(TYPE_USE) @interface D {} | ||
|
||
=== Outer.java === | ||
class Outer { | ||
Outer . Middle<@A Foo . @B Bar> . Inner<@D String @C []> f; | ||
|
||
class Middle<T> { | ||
class Inner<U> {} | ||
} | ||
|
||
class Foo { | ||
class Bar {} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
javatests/com/google/turbine/lower/testdata/type_anno_nested_raw.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== Annotations.java === | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(TYPE_USE) @interface A {} | ||
@Target(TYPE_USE) @interface B {} | ||
@Target(TYPE_USE) @interface C {} | ||
|
||
=== Outer.java === | ||
import java.util.List; | ||
|
||
class Outer { | ||
static class StaticMiddle<T> { | ||
class Inner<U> {} | ||
static class StaticInner<U> {} | ||
|
||
// raw types with parameterized enclosing types | ||
@A Inner a; | ||
@A StaticInner b; | ||
} | ||
|
||
Outer . StaticMiddle . @A Inner e; | ||
Outer . StaticMiddle . @A StaticInner f; | ||
Outer . StaticMiddle<@A String> . @B Inner<@C String> g; | ||
|
||
Outer . StaticMiddle<@A List> . @B Inner<@C List> h; | ||
List<Outer . StaticMiddle . @A StaticInner> i; | ||
|
||
// javac rejects these partially raw types | ||
// Outer . StaticMiddle<@A String> . @B Inner j; | ||
// Outer . StaticMiddle . @B Inner<@C String> k; | ||
} |