@@ -1346,7 +1346,7 @@ public boolean isSameType(Type t, Type s) {
13461346 * Type-equality relation - type variables are considered
13471347 * equals if they share the same object identity.
13481348 */
1349- TypeRelation isSameTypeVisitor = new TypeRelation () {
1349+ abstract class TypeEqualityVisitor extends TypeRelation {
13501350
13511351 public Boolean visitType (Type t , Type s ) {
13521352 if (t .equalsIgnoreMetadata (s ))
@@ -1385,10 +1385,12 @@ public Boolean visitWildcardType(WildcardType t, Type s) {
13851385 } else {
13861386 WildcardType t2 = (WildcardType )s ;
13871387 return (t .kind == t2 .kind || (t .isExtendsBound () && s .isExtendsBound ())) &&
1388- isSameType (t .type , t2 .type );
1388+ sameTypeComparator (t .type , t2 .type );
13891389 }
13901390 }
13911391
1392+ abstract boolean sameTypeComparator (Type t , Type s );
1393+
13921394 @ Override
13931395 public Boolean visitClassType (ClassType t , Type s ) {
13941396 if (t == s )
@@ -1419,9 +1421,11 @@ public Boolean visitClassType(ClassType t, Type s) {
14191421 }
14201422 return t .tsym == s .tsym
14211423 && visit (t .getEnclosingType (), s .getEnclosingType ())
1422- && containsTypeEquivalent (t .getTypeArguments (), s .getTypeArguments ());
1424+ && sameTypeArguments (t .getTypeArguments (), s .getTypeArguments ());
14231425 }
14241426
1427+ abstract boolean sameTypeArguments (List <Type > ts , List <Type > ss );
1428+
14251429 @ Override
14261430 public Boolean visitArrayType (ArrayType t , Type s ) {
14271431 if (t == s )
@@ -1477,6 +1481,16 @@ public Boolean visitUndetVar(UndetVar t, Type s) {
14771481 public Boolean visitErrorType (ErrorType t , Type s ) {
14781482 return true ;
14791483 }
1484+ }
1485+
1486+ TypeEqualityVisitor isSameTypeVisitor = new TypeEqualityVisitor () {
1487+ boolean sameTypeComparator (Type t , Type s ) {
1488+ return isSameType (t , s );
1489+ }
1490+
1491+ boolean sameTypeArguments (List <Type > ts , List <Type > ss ) {
1492+ return containsTypeEquivalent (ts , ss );
1493+ }
14801494 };
14811495
14821496 // </editor-fold>
@@ -3862,7 +3876,7 @@ public List<Type> intersect(List<Type> cl1, List<Type> cl2) {
38623876 // where
38633877 class TypePair {
38643878 final Type t1 ;
3865- final Type t2 ;;
3879+ final Type t2 ;
38663880
38673881 TypePair (Type t1 , Type t2 ) {
38683882 this .t1 = t1 ;
@@ -3875,10 +3889,28 @@ public int hashCode() {
38753889 @ Override
38763890 public boolean equals (Object obj ) {
38773891 return (obj instanceof TypePair typePair )
3878- && isSameType (t1 , typePair .t1 )
3879- && isSameType (t2 , typePair .t2 );
3892+ && exactTypeVisitor . visit (t1 , typePair .t1 )
3893+ && exactTypeVisitor . visit (t2 , typePair .t2 );
38803894 }
38813895 }
3896+
3897+ TypeEqualityVisitor exactTypeVisitor = new TypeEqualityVisitor () {
3898+ @ Override
3899+ boolean sameTypeArguments (List <Type > ts , List <Type > ss ) {
3900+ while (ts .nonEmpty () && ss .nonEmpty ()
3901+ && sameTypeComparator (ts .head , ss .head )) {
3902+ ts = ts .tail ;
3903+ ss = ss .tail ;
3904+ }
3905+ return ts .isEmpty () && ss .isEmpty ();
3906+ }
3907+
3908+ @ Override
3909+ boolean sameTypeComparator (Type t , Type s ) {
3910+ return exactTypeVisitor .visit (t , s );
3911+ }
3912+ };
3913+
38823914 Set <TypePair > mergeCache = new HashSet <>();
38833915 private Type merge (Type c1 , Type c2 ) {
38843916 ClassType class1 = (ClassType ) c1 ;
0 commit comments