From 6b2501317748eaf3ac5c61ad290d7569e637237d Mon Sep 17 00:00:00 2001 From: Suzanne Millstein Date: Thu, 10 Oct 2024 11:27:19 -0700 Subject: [PATCH] Fix crash. --- .../framework/util/AnnotatedTypes.java | 11 +++++++++++ framework/tests/all-systems/Issue6810.java | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 framework/tests/all-systems/Issue6810.java diff --git a/framework/src/main/java/org/checkerframework/framework/util/AnnotatedTypes.java b/framework/src/main/java/org/checkerframework/framework/util/AnnotatedTypes.java index 0ea32d0cdea..8a32cb9f7f7 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/AnnotatedTypes.java +++ b/framework/src/main/java/org/checkerframework/framework/util/AnnotatedTypes.java @@ -893,6 +893,17 @@ public static AnnotatedTypeMirror annotatedGLB( TypeMirror tm1 = type1.getUnderlyingType(); TypeMirror tm2 = type2.getUnderlyingType(); TypeMirror glbJava = TypesUtils.greatestLowerBound(tm1, tm2, atypeFactory.getProcessingEnv()); + if (glbJava.getKind() == TypeKind.ERROR) { + if (type1.getKind() == TypeKind.TYPEVAR) { + return type1; + } + if (type2.getKind() == TypeKind.TYPEVAR) { + return type2; + } + // I think the only way error happens is when one of the types is a typevarible, but just in + // case, just return type1. + return type1; + } Types types = atypeFactory.types; QualifierHierarchy qualHierarchy = atypeFactory.getQualifierHierarchy(); if (types.isSubtype(tm1, tm2)) { diff --git a/framework/tests/all-systems/Issue6810.java b/framework/tests/all-systems/Issue6810.java new file mode 100644 index 00000000000..2f19cb67677 --- /dev/null +++ b/framework/tests/all-systems/Issue6810.java @@ -0,0 +1,11 @@ +import java.util.Set; + +public class Issue6810 { + static class Box> {} + + abstract static class BoxSet> implements Set {} + + static > void intersect2(BoxSet intersect, Set set2) { + intersect.retainAll(set2); + } +}