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 26aa02c GROOVY-10128, GROOVY-10306: STC: simple covariace of
closure's primitive
26aa02c is described below
commit 26aa02c56833cc558cee29658028c817fa992e67
Author: Eric Milles <[email protected]>
AuthorDate: Sat Oct 30 10:06:40 2021 -0500
GROOVY-10128, GROOVY-10306: STC: simple covariace of closure's primitive
---
.../transform/stc/StaticTypeCheckingVisitor.java | 4 ++--
.../groovy/transform/stc/ClosuresSTCTest.groovy | 28 ++++++++++++++++++++--
2 files changed, 28 insertions(+), 4 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 d485fe8..31ae6d1 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2211,8 +2211,8 @@ public class StaticTypeCheckingVisitor extends
ClassCodeVisitorSupport {
type = STRING_TYPE; // GROOVY-9971: convert GString to String
at point of return
} else if (inferredReturnType != null
&& !GenericsUtils.hasUnresolvedGenerics(inferredReturnType)
- &&
GenericsUtils.buildWildcardType(inferredReturnType).isCompatibleWith(type)) {
- type = inferredReturnType; // GROOVY-8310, GROOVY-10082,
GROOVY-10091: allow simple covariance
+ &&
GenericsUtils.buildWildcardType(inferredReturnType).isCompatibleWith(wrapTypeIfNecessary(type)))
{
+ type = inferredReturnType; // GROOVY-8310, GROOVY-10082,
GROOVY-10091, GROOVY-10128, GROOVY-10306: allow simple covariance
}
return type;
}
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 798c291..5730d84 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -193,9 +193,33 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
'Cannot assign groovy.lang.Closure<X> to:
groovy.lang.Closure<A<java.lang.Number>>'
}
- // GROOVY-8427
+ // GROOVY-10128, GROOVY-10306
void testClosureReturnTypeInference8() {
assertScript '''
+ java.util.function.Function<String, Number> x = { s ->
+ long n = 1
+ return n
+ }
+ assert x.apply('') == 1L
+ '''
+ assertScript '''
+ class C {
+ byte p = 1
+ void m() {
+ byte v = 2
+ java.util.function.Supplier<Number> one = { -> p }
+ java.util.function.Supplier<Number> two = { -> v }
+ assert one.get() == (byte)1
+ assert two.get() == (byte)2
+ }
+ }
+ new C().m()
+ '''
+ }
+
+ // GROOVY-8427
+ void testClosureReturnTypeInference9() {
+ assertScript '''
import java.util.function.Consumer
class C {
@@ -216,7 +240,7 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
}
// GROOVY-8202
- void testClosureReturnTypeInference9() {
+ void testClosureReturnTypeInference10() {
assertScript '''
void proc() {
}