This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new aba0caea3a GROOVY-11559: fix `addAllInterfaces` for
`UnionTypeClassNode`
aba0caea3a is described below
commit aba0caea3a1c6c746182b7ba29f8bcbd8e516c14
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 | 23 +++++++++++++++++-----
2 files changed, 19 insertions(+), 6 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 c094dda188..45ce6c1ee3 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -275,7 +275,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 4f9069804c..4cf9527ff1 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -412,11 +412,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)
@@ -427,7 +427,20 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
}
}
+ // GROOVY-11559
void testMultipleInstanceOf5() {
+ assertScript '''
+ def foo(o) {
+ if (o instanceof Set || o instanceof List) {
+ o = "" // NullPointerException
+ }
+ }
+ foo("")
+ foo([])
+ '''
+ }
+
+ void testMultipleInstanceOf6() {
assertScript '''
void test(thing) {
if (thing instanceof Deque) {
@@ -445,8 +458,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
@@ -466,7 +479,7 @@ class TypeInferenceSTCTest extends
StaticTypeCheckingTestCase {
}
// GROOVY-8828
- void testMultipleInstanceOf7() {
+ void testMultipleInstanceOf8() {
assertScript '''
interface Foo { }
interface Bar { String name() }