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/09/23 18:14:32 UTC
[groovy] branch master updated: GROOVY-10256: STC: "Type x = m()"
given "def T m(); "
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 21122ce GROOVY-10256: STC: "Type x = m()" given "def <T extends NotType> T m();"
21122ce is described below
commit 21122ce43fe6f983d40e7c3c9632e1314047873b
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 23 13:12:33 2021 -0500
GROOVY-10256: STC: "Type x = m()" given "def <T extends NotType> T m();"
---
.../groovy/transform/stc/StaticTypeCheckingSupport.java | 4 ++--
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index fe45707..d79bcf6 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -749,8 +749,8 @@ public abstract class StaticTypeCheckingSupport {
return true;
}
- // GROOVY-7316: It is an apparently legal thing to allow this. It's not type safe, but it is allowed...
- return right.isGenericsPlaceHolder();
+ // GROOVY-7316, GROOVY-10256: "Type x = m()" given "def <T> T m()"; T adapts to target
+ return right.isGenericsPlaceHolder() && right.asGenericsType().isCompatibleWith(left);
}
private static boolean isGroovyConstructorCompatible(final Expression rightExpression) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 2e5d630..22001e2 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -453,8 +453,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
- // GROOVY-10098
+ // GROOVY-7316, GROOVY-10256
void testReturnTypeInferenceWithMethodGenerics16() {
+ shouldFailWithMessages '''
+ def <T extends CharSequence> T chars() {
+ }
+ List test() {
+ chars()
+ }
+ ''',
+ 'Cannot return value of type #T on method returning type java.util.List'
+ }
+
+ // GROOVY-10098
+ void testReturnTypeInferenceWithMethodGenerics17() {
assertScript '''
@groovy.transform.TupleConstructor(defaults=false)
class C<T extends Number> {
@@ -469,7 +481,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
}
// GROOVY-8638
- void testReturnTypeInferenceWithMethodGenerics17() {
+ void testReturnTypeInferenceWithMethodGenerics18() {
assertScript '''
@Grab('com.google.guava:guava:30.1.1-jre')
import com.google.common.collect.*