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

Don't recursively call combine and substitute if the underlining type is raw #788

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ protected AnnotatedTypeMirror combineAnnotationWithType(
AnnotationMirror resultAnnotation =
combineAnnotationWithAnnotation(
receiverAnnotation, extractAnnotationMirror(adt));

// Recursively combine type arguments and store to map
for (AnnotatedTypeMirror typeArgument : adt.getTypeArguments()) {
// Recursively adapt the type arguments of this adt
AnnotatedTypeMirror combinedTypeArgument =
combineAnnotationWithType(receiverAnnotation, typeArgument);
mappings.put(typeArgument, combinedTypeArgument);
// Don't recursively combine type arguments if the type is raw
if (!adt.isUnderlyingTypeRaw()) {
// Recursively combine type arguments and store to map
for (AnnotatedTypeMirror typeArgument : adt.getTypeArguments()) {
// Recursively adapt the type arguments of this adt
AnnotatedTypeMirror combinedTypeArgument =
combineAnnotationWithType(receiverAnnotation, typeArgument);
mappings.put(typeArgument, combinedTypeArgument);
}
}

// Construct result type
AnnotatedTypeMirror result = AnnotatedTypeCopierWithReplacement.replace(adt, mappings);
result.replaceAnnotation(resultAnnotation);
Expand Down Expand Up @@ -413,11 +414,14 @@ private AnnotatedTypeMirror substituteTVars(AnnotatedTypeMirror lhs, AnnotatedTy
AnnotatedDeclaredType adt = (AnnotatedDeclaredType) rhs.shallowCopy();
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> mappings =
new IdentityHashMap<>();

for (AnnotatedTypeMirror formalTypeParameter : adt.getTypeArguments()) {
AnnotatedTypeMirror actualTypeArgument = substituteTVars(lhs, formalTypeParameter);
mappings.put(formalTypeParameter, actualTypeArgument);
// The following code does the wrong thing!
// Don't recursively substitute type arguments if the type is raw
if (!adt.isUnderlyingTypeRaw()) {
for (AnnotatedTypeMirror formalTypeParameter : adt.getTypeArguments()) {
AnnotatedTypeMirror actualTypeArgument =
substituteTVars(lhs, formalTypeParameter);
mappings.put(formalTypeParameter, actualTypeArgument);
// The following code does the wrong thing!
}
}
// We must use AnnotatedTypeReplacer to replace the formal type parameters with actual
// type arguments, but not replace with its main qualifier
Expand Down
7 changes: 7 additions & 0 deletions framework/tests/viewpointtest/RawtypeInstantiation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test case for EISOP issue #778:
// https://github.com/eisop/checker-framework/issues/778
public class RawtypeInstantiation<A extends RawtypeInstantiation> {
void foo() {
RawtypeInstantiation rawtypeInstantiation = new RawtypeInstantiation();
}
}