Skip to content
Permalink
Browse files
STC: alignment of source and target
  • Loading branch information
eric-milles committed Mar 8, 2022
1 parent 6cb32bf commit 27885a716200f0211efc86b6cbdec8c888f574ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
@@ -555,16 +555,8 @@ public static void extractSuperClassGenerics(ClassNode type, ClassNode target, M
}
}

public static ClassNode getSuperClass(ClassNode type, ClassNode target) {
ClassNode superClass = ClassHelper.getNextSuperClass(type, target);

if (superClass == null) {
if (ClassHelper.isPrimitiveType(type)) {
superClass = ClassHelper.getNextSuperClass(ClassHelper.getWrapper(type), target);
}
}

return superClass;
public static ClassNode getSuperClass(final ClassNode type, final ClassNode target) {
return ClassHelper.getNextSuperClass(ClassHelper.isPrimitiveType(type) ? ClassHelper.getWrapper(type) : type, target);
}

private static void extractSuperClassGenerics(final GenericsType[] usage, final GenericsType[] declaration, final Map<String, ClassNode> spec) {
@@ -100,6 +100,7 @@
import static org.codehaus.groovy.ast.ClassHelper.double_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.findSAM;
import static org.codehaus.groovy.ast.ClassHelper.float_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.getNextSuperClass;
import static org.codehaus.groovy.ast.ClassHelper.getUnwrapper;
import static org.codehaus.groovy.ast.ClassHelper.getWrapper;
import static org.codehaus.groovy.ast.ClassHelper.int_TYPE;
@@ -120,7 +121,6 @@
import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching;
import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.void_WRAPPER_TYPE;
import static org.codehaus.groovy.ast.tools.GenericsUtils.makeClassSafe0;
import static org.codehaus.groovy.ast.tools.WideningCategories.isBigIntCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isFloatingCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
@@ -1454,7 +1454,7 @@ private static boolean typeCheckMethodsWithGenerics(final ClassNode receiver, fi
// GROOVY-8034: non-static method may use class generics
gts = applyGenericsContext(candidateGenerics, gts);
}
GenericsUtils.extractPlaceholders(makeClassSafe0(OBJECT_TYPE, gts), candidateGenerics);
GenericsUtils.extractPlaceholders(GenericsUtils.makeClassSafe0(OBJECT_TYPE, gts), candidateGenerics);

// the outside context parts till now define placeholder we are not allowed to
// generalize, thus we save that for later use...
@@ -1734,12 +1734,11 @@ static void extractGenericsConnections(final Map<GenericsTypeName, GenericsType>
ClassNode returnType = StaticTypeCheckingVisitor.wrapTypeIfNecessary(GenericsUtils.parameterizeSAM(target).getV2());
extractGenericsConnections(connections, type.getGenericsTypes(), new GenericsType[] {returnType.asGenericsType()});

} else if (type.equals(target) || !implementsInterfaceOrIsSubclassOf(type, target)) {
} else if (type.equals(target)) {
extractGenericsConnections(connections, type.getGenericsTypes(), target.getGenericsTypes());

} else {
// find matching super class or interface
ClassNode superClass = GenericsUtils.getSuperClass(type, target);
} else if (implementsInterfaceOrIsSubclassOf(type, target)) {
ClassNode superClass = getNextSuperClass(type, target);
if (superClass != null) {
if (GenericsUtils.hasUnresolvedGenerics(superClass)) {
Map<String, ClassNode> spec = GenericsUtils.createGenericsSpec(type);
@@ -1922,8 +1921,8 @@ static ClassNode getCombinedBoundType(final GenericsType genericsType) {
}

static GenericsType getCombinedGenericsType(final GenericsType gt1, final GenericsType gt2) {
ClassNode cn1 = makeClassSafe0(CLASS_Type, gt1);
ClassNode cn2 = makeClassSafe0(CLASS_Type, gt2);
ClassNode cn1 = GenericsUtils.makeClassSafe0(CLASS_Type, gt1);
ClassNode cn2 = GenericsUtils.makeClassSafe0(CLASS_Type, gt2);
ClassNode lub = lowestUpperBound(cn1,cn2);
return lub.getGenericsTypes()[0];
}
@@ -863,7 +863,10 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
} else if (!resultType.isGenericsPlaceHolder()) { // GROOVY-10324
Map<GenericsTypeName, GenericsType> gt = new HashMap<>();
extractGenericsConnections(gt, resultType, resultType.redirect());
extractGenericsConnections(gt, lType, getNextSuperClass(resultType, lType));
ClassNode sc = resultType;
do { sc = getNextSuperClass(sc, lType);
} while (sc != null && !sc.equals(lType));
extractGenericsConnections(gt, lType, sc);

resultType = applyGenericsContext(gt, resultType.redirect());// GROOVY-10235, et al.
}
@@ -2443,10 +2443,10 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
assertScript '''
@ASTTest(phase=INSTRUCTION_SELECTION, value={
def ift = node.getNodeMetaData(INFERRED_TYPE)
assert ift == make(List)
assert ift.isUsingGenerics()
assert ift == LIST_TYPE
def gts = ift.genericsTypes
assert gts.length==1
assert gts != null
assert gts.length == 1
assert gts[0].type == STRING_TYPE
})
Iterable<String> list = (List) null

0 comments on commit 27885a7

Please sign in to comment.