Skip to content
Permalink
Browse files
GROOVY-10363: STC: fix target type check for type parameter
  • Loading branch information
eric-milles committed May 16, 2022
1 parent 6b31aa6 commit 2632e241b39692ce6fbc16a6198ab638ab316c13
Showing 2 changed files with 14 additions and 3 deletions.
@@ -4225,8 +4225,8 @@ && isTypeSource(expr, enclosingMethod)) {

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());
@@ -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 '''

0 comments on commit 2632e24

Please sign in to comment.