Skip to content

Commit a3ab384

Browse files
committed
GROOVY-10280: STC: do not mix type param contexts when resolving
1 parent 27232f3 commit a3ab384

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,14 +1576,10 @@ private static void addMissingEntries(final Map<GenericsTypeName, GenericsType>
15761576
}
15771577

15781578
public static ClassNode resolveClassNodeGenerics(Map<GenericsTypeName, GenericsType> resolvedPlaceholders, final Map<GenericsTypeName, GenericsType> placeholdersFromContext, final ClassNode currentType) {
1579-
ClassNode target = currentType.redirect();
1580-
resolvedPlaceholders = new HashMap<>(resolvedPlaceholders);
1581-
applyContextGenerics(resolvedPlaceholders, placeholdersFromContext);
1582-
1583-
Map<GenericsTypeName, GenericsType> connections = new HashMap<>();
1584-
extractGenericsConnections(connections, currentType, target);
1585-
applyGenericsConnections(connections, resolvedPlaceholders);
1586-
return applyGenericsContext(resolvedPlaceholders, currentType);
1579+
ClassNode type = currentType; // GROOVY-10280, et al.
1580+
type = applyGenericsContext(resolvedPlaceholders, type);
1581+
type = applyGenericsContext(placeholdersFromContext, type);
1582+
return type;
15871583
}
15881584

15891585
static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> connections, final Map<GenericsTypeName, GenericsType> resolvedPlaceholders) {

src/test/groovy/transform/stc/GenericsSTCTest.groovy

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,21 +932,24 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
932932
assertScript '''
933933
class Test<T> {
934934
T test() {
935-
new Foo<T>().one.two.three
935+
@ASTTest(phase=INSTRUCTION_SELECTION, value={
936+
def type = node.getNodeMetaData(INFERRED_TYPE)
937+
assert type.toString(false) == 'T'
938+
})
939+
def t = new Foo<T>().x.y.z
936940
}
937941
}
938942
class Foo<X> {
939-
Bar<X> one = new Bar<>()
943+
Bar<X> x = new Bar<>()
940944
}
941-
class Bar<Y> {
942-
Baz<Y> two = new Baz<>()
945+
class Bar<T> {
946+
Baz<T> y = new Baz<>()
943947
}
944948
class Baz<Z> {
945-
Z three
949+
Z z
946950
}
947951
948-
def result = new Test().test()
949-
assert result == null
952+
new Test<String>().test()
950953
'''
951954
}
952955

0 commit comments

Comments
 (0)