Skip to content
Permalink
Browse files
GROOVY-10367: STC: diamond inference: skip type witness without generics
  • Loading branch information
eric-milles committed Mar 15, 2022
1 parent 01bb08e commit ff345d6b5de5a0ad4ad5d639d26c4e291542bef0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
@@ -1097,9 +1097,10 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
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);
@@ -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 '''

0 comments on commit ff345d6

Please sign in to comment.