From 368d71c45ab50a70f75ca6c1f1f3a29840ab220a Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Fri, 21 Jun 2024 18:20:14 -0400 Subject: [PATCH 1/3] Add test case (expect failure) --- framework/tests/viewpointtest/Generics.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 framework/tests/viewpointtest/Generics.java diff --git a/framework/tests/viewpointtest/Generics.java b/framework/tests/viewpointtest/Generics.java new file mode 100644 index 00000000000..511768b3178 --- /dev/null +++ b/framework/tests/viewpointtest/Generics.java @@ -0,0 +1,7 @@ +// Test case for EISOP issue #778: +// https://github.com/eisop/checker-framework/issues/778 +public class Generics> { + void foo() { + Generics generics = new Generics(); + } +} From 13bd97bb8f1514e52222c278af31c81ba42f7edd Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Mon, 19 Aug 2024 15:45:18 -0400 Subject: [PATCH 2/3] Rename the test case --- framework/tests/viewpointtest/Generics.java | 7 ------- framework/tests/viewpointtest/RawtypeInstantiation.java | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 framework/tests/viewpointtest/Generics.java create mode 100644 framework/tests/viewpointtest/RawtypeInstantiation.java diff --git a/framework/tests/viewpointtest/Generics.java b/framework/tests/viewpointtest/Generics.java deleted file mode 100644 index 511768b3178..00000000000 --- a/framework/tests/viewpointtest/Generics.java +++ /dev/null @@ -1,7 +0,0 @@ -// Test case for EISOP issue #778: -// https://github.com/eisop/checker-framework/issues/778 -public class Generics> { - void foo() { - Generics generics = new Generics(); - } -} 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(); + } +} From 718847cd78021296a68db29d0b7d9be2935c4331 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Mon, 19 Aug 2024 15:45:45 -0400 Subject: [PATCH 3/3] 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