From 718847cd78021296a68db29d0b7d9be2935c4331 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Mon, 19 Aug 2024 15:45:45 -0400 Subject: [PATCH] Don't recursively call the function if the underlining type is raw --- .../type/AbstractViewpointAdapter.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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