diff --git a/framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java b/framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java index d85f0814579..b764f6d38a7 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java +++ b/framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java @@ -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); @@ -413,11 +414,14 @@ private AnnotatedTypeMirror substituteTVars(AnnotatedTypeMirror lhs, AnnotatedTy AnnotatedDeclaredType adt = (AnnotatedDeclaredType) rhs.shallowCopy(); IdentityHashMap 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 diff --git a/framework/tests/viewpointtest/RawtypeInstantiation.java b/framework/tests/viewpointtest/RawtypeInstantiation.java new file mode 100644 index 00000000000..f071c136f77 --- /dev/null +++ b/framework/tests/viewpointtest/RawtypeInstantiation.java @@ -0,0 +1,7 @@ +// Test case for EISOP issue #778: +// https://github.com/eisop/checker-framework/issues/778 +public class RawtypeInstantiation { + void foo() { + RawtypeInstantiation rawtypeInstantiation = new RawtypeInstantiation(); + } +}