Skip to content

Commit 9f73dbc

Browse files
committed
GROOVY-11559: fix addAllInterfaces for UnionTypeClassNode
1 parent d5b22aa commit 9f73dbc

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static ClassNode parameterizeType(ClassNode hint, final ClassNode target)
274274
Map<String, ClassNode> gt;
275275

276276
// relationship may be reversed for cases like "Iterable<String> x = []"
277-
if (!cn.equals(hint) && implementsInterfaceOrIsSubclassOf(target, hint)) {
277+
if (!cn.equals(hint) && (hint.isInterface() ? cn.implementsInterface(hint) : cn.isDerivedFrom(hint))) { // GROOVY-11559
278278
do { // walk target type hierarchy towards hint
279279
cn = ClassHelper.getNextSuperClass(cn, hint);
280280
if (hasUnresolvedGenerics(cn)) {

src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy

+19-6
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
414414

415415
// GROOVY-8965
416416
void testMultipleInstanceOf4() {
417-
['o', '((Number) o)'].each {
417+
for (o in ['o', '((Number) o)']) {
418418
assertScript """
419419
def foo(o) {
420420
if (o instanceof Integer || o instanceof Double) {
421-
${it}.floatValue() // ClassCastException
421+
${o}.floatValue() // ClassCastException
422422
}
423423
}
424424
def bar = foo(1.1d)
@@ -429,8 +429,21 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
429429
}
430430
}
431431

432-
@NotYetImplemented
432+
// GROOVY-11559
433433
void testMultipleInstanceOf5() {
434+
assertScript '''
435+
def foo(o) {
436+
if (o instanceof Set || o instanceof List) {
437+
o = "" // NullPointerException
438+
}
439+
}
440+
foo("")
441+
foo([])
442+
'''
443+
}
444+
445+
@NotYetImplemented
446+
void testMultipleInstanceOf6() {
434447
assertScript '''
435448
void test(thing) {
436449
if (thing instanceof Deque) {
@@ -448,8 +461,8 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
448461
}
449462

450463
// GROOVY-10668
451-
void testMultipleInstanceOf6() {
452-
['(value as String)', 'value.toString()'].each { string ->
464+
void testMultipleInstanceOf7() {
465+
for (string in ['(value as String)', 'value.toString()']) {
453466
assertScript """
454467
def toArray(Object value) {
455468
def array
@@ -469,7 +482,7 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
469482
}
470483

471484
// GROOVY-8828
472-
void testMultipleInstanceOf7() {
485+
void testMultipleInstanceOf8() {
473486
assertScript '''
474487
interface Foo { }
475488
interface Bar { String name() }

0 commit comments

Comments
 (0)