Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializes all fields of newly created ATM before substituting type vars. #4850

Merged
merged 4 commits into from Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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<Void, Void> 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.
Expand Down
Expand Up @@ -210,7 +210,7 @@ public List<AnnotatedDeclaredType> visitDeclared(AnnotatedDeclaredType type, Voi

List<AnnotatedDeclaredType> 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));
}
Expand Down
21 changes: 21 additions & 0 deletions 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<T> {}

abstract class Issue4849C<F1> extends Issue4849G<Issue4849C<F1>> {}

abstract class Issue4849G<M extends Issue4849G<M>> {
abstract M e();
}

@SuppressWarnings("all") // Just check for crashes.
abstract class Issue4849 {
enum MyEnum {}

abstract <F1> Issue4849C<F1> n(Issue4849F<F1> field1);

abstract <E extends Enum<E>> Issue4849F<E> of(Class<E> e);

void method() {
Issue4849C<MyEnum> c = this.n(this.of(MyEnum.class)).e();
}
}