diff --git a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java index 85eac1e5059..02af5cd0064 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java +++ b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java @@ -327,6 +327,20 @@ public class AnnotatedTypeFactory implements AnnotationProvider { /** Map keys are canonical names of aliased annotations. */ private final Map<@FullyQualifiedName String, Alias> aliases = new HashMap<>(); + /** + * Scans all parts of the {@link AnnotatedTypeMirror} so that all of its fields are initialized. + */ + private SimpleAnnotatedTypeScanner atmInitializer = + new SimpleAnnotatedTypeScanner<>((type1, q) -> null); + + /** + * Initializes all fields of {@code type}. + * + * @param type annotated type mirror + */ + public void initializeAtm(AnnotatedTypeMirror type) { + atmInitializer.visit(type); + } /** * Information about one annotation alias. diff --git a/framework/src/main/java/org/checkerframework/framework/type/SupertypeFinder.java b/framework/src/main/java/org/checkerframework/framework/type/SupertypeFinder.java index a99db313b36..5c2e3e7ade7 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/SupertypeFinder.java +++ b/framework/src/main/java/org/checkerframework/framework/type/SupertypeFinder.java @@ -210,7 +210,7 @@ public List visitDeclared(AnnotatedDeclaredType type, Voi List superTypesNew = new ArrayList<>(); for (AnnotatedDeclaredType dt : supertypes) { - dt.getTypeArguments(); // Initialize the type arguments. + type.atypeFactory.initializeAtm(dt); superTypesNew.add( (AnnotatedDeclaredType) atypeFactory.getTypeVarSubstitutor().substitute(mapping, dt)); } diff --git a/framework/tests/all-systems/Issue4849.java b/framework/tests/all-systems/Issue4849.java new file mode 100644 index 00000000000..972bb4dea11 --- /dev/null +++ b/framework/tests/all-systems/Issue4849.java @@ -0,0 +1,21 @@ +// The error is reproducable none of the classes are not inner classes. +final class Issue4849F {} + +abstract class Issue4849C extends Issue4849G> {} + +abstract class Issue4849G> { + abstract M e(); +} + +@SuppressWarnings("all") // Just check for crashes. +abstract class Issue4849 { + enum MyEnum {} + + abstract Issue4849C n(Issue4849F field1); + + abstract > Issue4849F of(Class e); + + void method() { + Issue4849C c = this.n(this.of(MyEnum.class)).e(); + } +}