You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/03/15 17:37:53 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10367: STC: diamond inference: skip type witness without generics
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 3e18584 GROOVY-10367: STC: diamond inference: skip type witness without generics
3e18584 is described below
commit 3e1858480238cd9d6a9a78566860d1cadb6c7696
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Mar 15 12:06:00 2022 -0500
GROOVY-10367: STC: diamond inference: skip type witness without generics
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 5 +++--
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 14 ++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
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 f9dee30..8a49279 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1097,9 +1097,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (!argumentList.getExpressions().isEmpty() && constructor != null) {
ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
type = inferReturnTypeGenerics(type, constructor, argumentList);
- if (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291, GROOVY-10368
+ if (lType.getGenericsTypes() != null // GROOVY-10367: nothing to inspect
+ && (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291, GROOVY-10368: unresolved generic
// GROOVY-6232, GROOVY-9956: if cce not assignment compatible, process target as additional type witness
- || checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildcardType(lType).isCompatibleWith(type)) {
+ || checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildcardType(lType).isCompatibleWith(type))) {
// allow covariance of each type parameter, but maintain semantics for nested generics
ClassNode pType = GenericsUtils.parameterizeType(lType, type);
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 363c2f0..3316fd7 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1182,6 +1182,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
}
}
+ // GROOVY-10367
+ void testDiamondInferrenceFromConstructor26() {
+ assertScript '''
+ @groovy.transform.TupleConstructor(defaults=false)
+ class C<X, Y extends X> { // works without Y
+ X x
+ }
+ def <Z extends Number> void test(Z z) {
+ z = new C<>(z).x // Cannot assign value of type Object to variable of type Z
+ }
+ test(null)
+ '''
+ }
+
// GROOVY-10280
void testTypeArgumentPropagation() {
assertScript '''