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/05/16 15:09:52 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10363: STC: fix target type check for type parameter
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 1dd2e4f7e7 GROOVY-10363: STC: fix target type check for type parameter
1dd2e4f7e7 is described below
commit 1dd2e4f7e76523f894e6219782a910870338d100
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon May 16 09:55:24 2022 -0500
GROOVY-10363: STC: fix target type check for type parameter
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++--
src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy | 13 ++++++++++++-
2 files changed, 14 insertions(+), 3 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 95714c9ee4..fb1b8ce0c1 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4219,8 +4219,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (targetType == null) return sourceType;
- if (!isPrimitiveType(getUnwrapper(targetType))
- && !isObjectType(targetType) && missesGenericsTypes(sourceType)) {
+ if (!isPrimitiveType(getUnwrapper(targetType)) && !isObjectType(targetType)
+ && !sourceType.isGenericsPlaceHolder() && missesGenericsTypes(sourceType)) {
// unchecked assignment with ternary/elvis, like "List<T> list = listOfT ?: []"
// the inferred type is the RHS type "completed" with generics information from LHS
return GenericsUtils.parameterizeType(targetType, sourceType.getPlainNodeReference());
diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 93de510c9c..7fd3ab0fe2 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -134,7 +134,7 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
}
// GROOVY-10330
- void testTypeParameterTypeParameter() {
+ void testTypeParameterTypeParameter1() {
assertScript '''
class C<T> {
T y
@@ -155,6 +155,17 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10363
+ void testTypeParameterTypeParameter2() {
+ assertScript '''
+ def <X extends java.util.function.Supplier<Number>> X m(X x, X y) {
+ X z = true ? x : y // z infers as Supplier<Object>
+ return z
+ }
+ assert m(null,null) == null
+ '''
+ }
+
// GROOVY-10357
void testAbstractMethodDefault() {
assertScript '''