Skip to content
Permalink
Browse files
GROOVY-10316: STC: don't apply context generics for diamond ctor call
  • Loading branch information
eric-milles committed May 17, 2022
1 parent b66abe4 commit 581e54b1e906a406d08ee330f7d812854f04a967
Showing 2 changed files with 18 additions and 1 deletion.
@@ -232,6 +232,7 @@
import static org.codehaus.groovy.ast.tools.WideningCategories.isLongCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.init;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last;
import static org.codehaus.groovy.syntax.Types.ASSIGN;
@@ -2282,7 +2283,7 @@ && findMethod(receiver, "<init>", init(argumentTypes)).size() == 1) {
ctor = findMethodOrFail(call, receiver, "<init>", argumentTypes);
if (ctor != null) {
Parameter[] parameters = ctor.getParameters();
if (receiver.getGenericsTypes() != null) { // GROOVY-8909, GROOVY-9734, GROOVY-9844, GROOVY-9915, GROOVY-10482, et al.
if (asBoolean(receiver.getGenericsTypes())) { // GROOVY-10283, GROOVY-10316, GROOVY-10482, et al.
Map<GenericsTypeName, GenericsType> context = extractPlaceHoldersVisibleToDeclaration(receiver, ctor, argumentList);
parameters = Arrays.stream(parameters).map(p -> new Parameter(applyGenericsContext(context, p.getType()), p.getName())).toArray(Parameter[]::new);
}
@@ -1317,6 +1317,22 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}

// GROOVY-10316
void testDiamondInferrenceFromConstructor28() {
assertScript '''
class A<T> {
A(T t) {
}
}
@groovy.transform.TupleConstructor(defaults=false)
class B<T> {
A<T> p
}
def b = new B<>(new A<>(1L))
A<Long> x = b.p // Cannot assign A<Object> to: A<Long>
'''
}

// GROOVY-10280
void testTypeArgumentPropagation() {
assertScript '''

0 comments on commit 581e54b

Please sign in to comment.