[
https://issues.apache.org/jira/browse/GROOVY-11888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18069979#comment-18069979
]
ASF GitHub Bot commented on GROOVY-11888:
-----------------------------------------
eric-milles commented on code in PR #2415:
URL: https://github.com/apache/groovy/pull/2415#discussion_r3016831614
##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java:
##########
@@ -965,6 +965,8 @@ public static List<MethodNode> chooseBestMethod(final
ClassNode receiver, Collec
var view = methods;
if (duckType) {
view = methods.stream().filter(m ->
implementsInterfaceOrSubclassOf(rcvr, m.getDeclaringClass())).toList();
+ if (view.size() > 1)
+ view = removeCovariantsAndInterfaceEquivalents(view, true);
Review Comment:
Can you add a GROOVY-11888 comment to this line?
> 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)