This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 9f73dbc435 GROOVY-11559: fix `addAllInterfaces` for
`UnionTypeClassNode`
9f73dbc435 is described below
commit 9f73dbc4356baa7707ea68ef53580454dff638ad
Author: Eric Milles <[email protected]>
AuthorDate: Sun Jan 26 16:02:10 2025 -0600
GROOVY-11559: fix `addAllInterfaces` for `UnionTypeClassNode`
---
.../codehaus/groovy/ast/tools/GenericsUtils.java | 2 +-
.../transform/stc/TypeInferenceSTCTest.groovy | 25 ++++++++++++++++------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 129e697226..e5c7078224 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -274,7 +274,7 @@ public class GenericsUtils {
Map<String, ClassNode> gt;
// relationship may be reversed for cases like "Iterable<String> x =
[]"
- if (!cn.equals(hint) && implementsInterfaceOrIsSubclassOf(target,
hint)) {
+ if (!cn.equals(hint) && (hint.isInterface() ?
cn.implementsInterface(hint) : cn.isDerivedFrom(hint))) { // GROOVY-11559
do { // walk target type hierarchy towards hint
cn = ClassHelper.getNextSuperClass(cn, hint);
if (hasUnresolvedGenerics(cn)) {
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index 4caa5a22c2..c2e0e53f02 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -414,11 +414,11 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
// GROOVY-8965
void testMultipleInstanceOf4() {
- ['o', '((Number) o)'].each {
+ for (o in ['o', '((Number) o)']) {
assertScript """
def foo(o) {
if (o instanceof Integer || o instanceof Double) {
- ${it}.floatValue() // ClassCastException
+ ${o}.floatValue() // ClassCastException
}
}
def bar = foo(1.1d)
@@ -429,8 +429,21 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
}
}
- @NotYetImplemented
+ // GROOVY-11559
void testMultipleInstanceOf5() {
+ assertScript '''
+ def foo(o) {
+ if (o instanceof Set || o instanceof List) {
+ o = "" // NullPointerException
+ }
+ }
+ foo("")
+ foo([])
+ '''
+ }
+
+ @NotYetImplemented
+ void testMultipleInstanceOf6() {
assertScript '''
void test(thing) {
if (thing instanceof Deque) {
@@ -448,8 +461,8 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
}
// GROOVY-10668
- void testMultipleInstanceOf6() {
- ['(value as String)', 'value.toString()'].each { string ->
+ void testMultipleInstanceOf7() {
+ for (string in ['(value as String)', 'value.toString()']) {
assertScript """
def toArray(Object value) {
def array
@@ -469,7 +482,7 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
}
// GROOVY-8828
- void testMultipleInstanceOf7() {
+ void testMultipleInstanceOf8() {
assertScript '''
interface Foo { }
interface Bar { String name() }