Skip to content

Commit

Permalink
Fix for #1360: GROOVY-10624
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 17, 2022
1 parent 5c87c7b commit 1061842
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5645,4 +5645,25 @@ public void testTypeChecked10592() {

runConformTest(sources, "works", "groovy.lang.MissingPropertyException: No such property: value for class: Face");
}

@Test
public void testTypeChecked10624() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class A<T> {\n" +
"}\n" +
"class B<T> {\n" +
" B(A<T> a) { }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" B<Float> x = new B<>(new A<>())\n" + // Cannot assign B<Object> to B<Float>
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,7 @@ && findMethod(receiver, "<init>", init(argumentTypes)).size() == 1) {
&& parameters.length == argumentTypes.length - 1) {
ctor = typeCheckMapConstructor(call, receiver, arguments);
} else {
if (parameters.length > 0 && receiver.getGenericsTypes() != null) { // GROOVY-8961, GROOVY-9734, GROOVY-9915, GROOVY-10482, et al.
if (parameters.length > 0 && asBoolean(receiver.getGenericsTypes())) { // GROOVY-10283, GROOVY-10316, GROOVY-10482, GROOVY-10624, et al.
Map<GenericsTypeName, GenericsType> context = extractPlaceHolders(null, receiver, ctor.getDeclaringClass());
parameters = parameters.clone(); for (int i = 0; i < parameters.length; i += 1)
parameters[i] = new Parameter(applyGenericsContext(context, parameters[i].getType()), parameters[i].getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound;
import static org.codehaus.groovy.classgen.AsmClassGenerator.MINIMUM_BYTECODE_VERSION;
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;
Expand Down Expand Up @@ -2636,7 +2637,7 @@ && findMethod(receiver, "<init>", init(argumentTypes)).size() == 1) {
&& parameters.length == argumentTypes.length - 1) {
ctor = typeCheckMapConstructor(call, receiver, arguments);
} else {
if (receiver.getGenericsTypes() != null) { // GROOVY-8961, GROOVY-9734, GROOVY-9915, GROOVY-10482, et al.
if (asBoolean(receiver.getGenericsTypes())) { // GROOVY-10283, GROOVY-10316, GROOVY-10482, GROOVY-10624, et al.
Map<GenericsTypeName, GenericsType> context = extractPlaceHolders(null, receiver, ctor.getDeclaringClass());
parameters = Arrays.stream(parameters).map(p -> new Parameter(applyGenericsContext(context, p.getType()), p.getName())).toArray(Parameter[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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;
Expand Down Expand Up @@ -2319,7 +2320,7 @@ && findMethod(receiver, "<init>", init(argumentTypes)).size() == 1) {
&& parameters.length == argumentTypes.length - 1) {
ctor = typeCheckMapConstructor(call, receiver, arguments);
} else {
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, GROOVY-10624, 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);
}
Expand Down

0 comments on commit 1061842

Please sign in to comment.