[ 
https://issues.apache.org/jira/browse/GROOVY-11888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18069978#comment-18069978
 ] 

ASF GitHub Bot commented on GROOVY-11888:
-----------------------------------------

eric-milles commented on code in PR #2415:
URL: https://github.com/apache/groovy/pull/2415#discussion_r3016829805


##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java:
##########
@@ -953,8 +953,8 @@ public static List<MethodNode> chooseBestMethod(final 
ClassNode receiver, Collec
 
         // GROOVY-8965: type disjunction
         boolean duckType = receiver instanceof UnionTypeClassNode;
-        if (methods.size() > 1 && !first(methods).isConstructor())
-            methods = removeCovariantsAndInterfaceEquivalents(methods, 
duckType);
+        if (!duckType && methods.size() > 1 && !first(methods).isConstructor())
+            methods = removeCovariantsAndInterfaceEquivalents(methods, false);
 
         if (!duckType && argumentTypes == null) {
             return asList(methods); // GROOVY-11683: no covariants or 
equivalents

Review Comment:
   Can you combine with this block?  
   ```java
           if (!duckType) {
               if (methods.size() > 1 && !first(methods).isConstructor())
                   methods = removeCovariantsAndInterfaceEquivalents(methods, 
false);
               if (argumentTypes == null)
                   return asList(methods); // GROOVY-11683: no covariants or 
equivalents
           }
   ```





> STC: method resolution fails for UnionTypeClassNode due to premature 
> covariant elimination
> ------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11888
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11888
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> The following {{instanceof}} checks worked under Groovy 5 and are failing 
> under Groovy 6 (alpha):
> {code:groovy}
> @CompileStatic test24(Object x) {
>   if (x instanceof String || x instanceof List) {
>     assert x.toString() != null
>   }
> }
> test24('hello')
> test24([1, 2])
> @CompileStatic test25(Object x) {
>   if (!(x instanceof String || x instanceof Integer)) {
>     assert x != null
>   } else {
>     assert x instanceof String || x instanceof Integer
>   }
> }
> test25('hello')
> test25(42)
> test25(3.14)
> {code}
> This case works under Groovy 4, fails under Groovy 5 (see GROOVY-11754) but 
> is expected to work for Groovy 6 (alpha):
> {code:groovy}
> @CompileStatic test26(Number n) {
>   if (n instanceof Integer || n.intValue() > 0) {
>     assert n.intValue() >= 0 // Cannot find matching method 
> (java.lang.Integer | java.lang.Number)#intValue()
>   }
> }
> test26(42)
> test26(1.5)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to