Skip to content

Commit 308270c

Browse files
committed
GROOVY-11888: STC: method resolution fails for UnionTypeClassNode due to premature covariant elimination
1 parent 3a4978d commit 308270c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,20 +953,21 @@ public static List<MethodNode> chooseBestMethod(final ClassNode receiver, Collec
953953

954954
// GROOVY-8965: type disjunction
955955
boolean duckType = receiver instanceof UnionTypeClassNode;
956-
if (!duckType && methods.size() > 1 && !first(methods).isConstructor())
957-
methods = removeCovariantsAndInterfaceEquivalents(methods, false);
958-
959-
if (!duckType && argumentTypes == null) {
960-
return asList(methods); // GROOVY-11683: no covariants or equivalents
956+
if (!duckType) {
957+
if (methods.size() > 1 && !first(methods).isConstructor())
958+
methods = removeCovariantsAndInterfaceEquivalents(methods, false);
959+
if (argumentTypes == null)
960+
return asList(methods); // GROOVY-11683: no covariants or equivalents
961961
}
962962

963963
Set<MethodNode> bestMethods = new HashSet<>(); // choose best method(s) for each possible receiver
964964
for (ClassNode rcvr : duckType ? ((UnionTypeClassNode) receiver).getDelegates() : new ClassNode[]{receiver}) {
965965
var view = methods;
966966
if (duckType) {
967967
view = methods.stream().filter(m -> implementsInterfaceOrSubclassOf(rcvr, m.getDeclaringClass())).toList();
968-
if (view.size() > 1 && !first(view).isConstructor())
968+
if (view.size() > 1) { // GROOVY-11888
969969
view = removeCovariantsAndInterfaceEquivalents(view, true);
970+
}
970971
}
971972
view = chooseBestMethods(rcvr, view, argumentTypes);
972973
if (view.isEmpty()) {

0 commit comments

Comments
 (0)