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 2021/08/18 15:41:27 UTC
[groovy] 01/03: GROOVY-9915: use type(s) from static call site to
resolve generics
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit fffe63ff8694896022210348547d0ebebb56fc6e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Jan 27 10:23:15 2021 -0600
GROOVY-9915: use type(s) from static call site to resolve generics
---
.../transform/stc/StaticTypeCheckingVisitor.java | 5 +-
.../groovy/transform/stc/GenericsSTCTest.groovy | 118 +++++++++++----------
2 files changed, 65 insertions(+), 58 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 ed0c92c..f6d1b19 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2619,8 +2619,11 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
for (Receiver<String> currentReceiver : receivers) {
mn = findMethod(currentReceiver.getType(), name, args);
if (!mn.isEmpty()) {
- if (mn.size() == 1)
+ if (mn.size() == 1) {
+ // GROOVY-8961, GROOVY-9734, GROOVY-9915
+ resolvePlaceholdersFromImplicitTypeHints(args, argumentList, mn.get(0));
typeCheckMethodsWithGenericsOrFail(currentReceiver.getType(), args, mn.get(0), call);
+ }
chosenReceiver = currentReceiver;
break;
}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 0f29974..13483df 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -665,68 +665,72 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
''', 'Cannot call <X> groovy.transform.stc.GenericsSTCTest$ClassA <Long>#bar(java.lang.Class <Long>) with arguments [java.lang.Class <? extends java.lang.Object>]'
}
- // GROOVY-8961
+ // GROOVY-8961, GROOVY-9915
void testShouldUseMethodGenericType3() {
- assertScript '''
- void setM(List<String> strings) {
- }
- void test() {
- m = Collections.emptyList() // Cannot assign value of type List<T> to variable of List<String>
- }
- test()
- '''
- assertScript '''
- void setM(Collection<String> strings) {
- }
- void test() {
- m = Collections.emptyList()
- }
- test()
- '''
- assertScript '''
- void setM(Iterable<String> strings) {
- }
- void test() {
- m = Collections.emptyList()
- }
- test()
- '''
+ ['', 'static'].each { mods ->
+ assertScript """
+ $mods void setM(List<String> strings) {
+ }
+ void test() {
+ m = Collections.emptyList() // Cannot assign value of type List<T> to variable of List<String>
+ }
+ test()
+ """
+ assertScript """
+ $mods void setM(Collection<String> strings) {
+ }
+ void test() {
+ m = Collections.emptyList()
+ }
+ test()
+ """
+ assertScript """
+ $mods void setM(Iterable<String> strings) {
+ }
+ void test() {
+ m = Collections.emptyList()
+ }
+ test()
+ """
- shouldFailWithMessages '''
- void setM(List<String> strings) {
- }
- void test() {
- m = Collections.<Integer>emptyList()
- }
- ''', '[Static type checking] - Cannot assign value of type java.util.List <Integer> to variable of type java.util.List <String>'
+ shouldFailWithMessages """
+ $mods void setM(List<String> strings) {
+ }
+ void test() {
+ m = Collections.<Integer>emptyList()
+ }
+ """, '[Static type checking] - Cannot assign value of type java.util.List <Integer> to variable of type java.util.List <String>'
+ }
}
- // GROOVY-9734
+ // GROOVY-9734, GROOVY-9915
void testShouldUseMethodGenericType4() {
- assertScript '''
- void m(List<String> strings) {
- }
- void test() {
- m(Collections.emptyList()) // Cannot call m(List<String>) with arguments [List<T>]
- }
- test()
- '''
- assertScript '''
- void m(Collection<String> strings) {
- }
- void test() {
- m(Collections.emptyList())
- }
- test()
- '''
- assertScript '''
- void m(Iterable<String> strings) {
- }
- void test() {
- m(Collections.emptyList())
- }
- test()
- '''
+ ['', 'static'].each { mods ->
+ assertScript """
+ $mods void m(List<String> strings) {
+ }
+ void test() {
+ m(Collections.emptyList()) // Cannot call m(List<String>) with arguments [List<T>]
+ }
+ test()
+ """
+ assertScript """
+ $mods void m(Collection<String> strings) {
+ }
+ void test() {
+ m(Collections.emptyList())
+ }
+ test()
+ """
+ assertScript """
+ $mods void m(Iterable<String> strings) {
+ }
+ void test() {
+ m(Collections.emptyList())
+ }
+ test()
+ """
+ }
}
// GROOVY-9751