Skip to content

Commit 3306448

Browse files
committed
GROOVY-11711: restore outer class generics after inner class visit
4_0_X backport
1 parent 8f74d9d commit 3306448

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/main/java/org/codehaus/groovy/control/ResolveVisitor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,14 @@ public void visitClass(final ClassNode node) {
12721272

12731273
//
12741274

1275-
if (!(node instanceof InnerClassNode) || Modifier.isStatic(node.getModifiers())) {
1275+
Map<GenericsTypeName, GenericsType> outerNames = null;
1276+
if (node instanceof InnerClassNode) {
1277+
outerNames = genericParameterNames;
12761278
genericParameterNames = new HashMap<>();
1279+
if (!Modifier.isStatic(node.getModifiers()))
1280+
genericParameterNames.putAll(outerNames); // outer names visible
1281+
} else {
1282+
genericParameterNames.clear(); // outer class: new generic namespace
12771283
}
12781284
resolveGenericsHeader(node.getGenericsTypes());
12791285
switch (phase) { // GROOVY-9866, GROOVY-10466
@@ -1316,6 +1322,7 @@ public void visitClass(final ClassNode node) {
13161322
visitObjectInitializerStatements(node);
13171323
visitAnnotations(node); // GROOVY-10750, GROOVY-11206
13181324
}
1325+
if (outerNames != null) genericParameterNames = outerNames;
13191326
currentClass = oldNode;
13201327
}
13211328

src/test/groovy/gls/innerClass/InnerClassTest.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,25 @@ final class InnerClassTest {
12651265
assert err =~ /No enclosing instance passed in constructor call of a non-static inner class/
12661266
}
12671267

1268+
// GROOVY-11711
1269+
@Test
1270+
void testUsageOfOuterType6() {
1271+
assertScript '''
1272+
class Foo<T> {
1273+
static class Bar {
1274+
}
1275+
/*non-static*/ class Baz
1276+
implements java.util.concurrent.Callable<T> {
1277+
T call() {
1278+
}
1279+
}
1280+
}
1281+
def foo = new Foo<Short>()
1282+
def baz = new Foo.Baz(foo)
1283+
assert baz.call() == null
1284+
'''
1285+
}
1286+
12681287
@Test
12691288
void testClassOutputOrdering() {
12701289
// this does actually not do much, but before this

0 commit comments

Comments
 (0)