This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 1e087f8 GROOVY-10339: STC: incorporate additional type witnesses for
method call
1e087f8 is described below
commit 1e087f8d9df4520e896f82f667efab1fe7446105
Author: Eric Milles <[email protected]>
AuthorDate: Sat Nov 6 11:57:16 2021 +1000
GROOVY-10339: STC: incorporate additional type witnesses for method call
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 5 ++++-
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index af6d035..4a26bf9 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5352,7 +5352,10 @@ public class StaticTypeCheckingVisitor extends
ClassCodeVisitorSupport {
Map<GenericsTypeName, GenericsType> connections = new
HashMap<>();
extractGenericsConnections(connections,
wrapTypeIfNecessary(argumentType), paramType);
connections.forEach((gtn, gt) ->
resolvedPlaceholders.merge(gtn, gt, (gt1, gt2) -> {
- return gt2; // TODO
+ // GROOVY-10339: incorporate additional witness
+ ClassNode cn1 = makeClassSafe0(CLASS_Type, gt1);
+ ClassNode cn2 = makeClassSafe0(CLASS_Type, gt2);
+ return
lowestUpperBound(cn1,cn2).getGenericsTypes()[0];
}));
}
}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 9790d26..9482905 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -559,6 +559,18 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10339
+ void testReturnTypeInferenceWithMethodGenerics21() {
+ shouldFailWithMessages '''
+ String foo() {
+ }
+ def <T> T bar(T x, T y) {
+ }
+ Integer i = bar(foo(), 1)
+ ''',
+ 'Cannot assign value of type'
+ }
+
void testDiamondInferrenceFromConstructor1() {
assertScript '''
class Foo<U> {