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 2022/05/16 15:44:44 UTC
[groovy] 01/02: GROOVY-10230, GROOVY-10330: given type param `T`, LUB(`T`,`T`) is `T`
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 1e3434dfe4c178eead4efb96bcfcb42019f9f59c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Oct 30 10:51:57 2021 -0500
GROOVY-10230, GROOVY-10330: given type param `T`, LUB(`T`,`T`) is `T`
---
.../groovy/ast/tools/WideningCategories.java | 8 +++++---
.../groovy/transform/stc/GenericsSTCTest.groovy | 2 +-
.../transform/stc/TernaryOperatorSTCTest.groovy | 22 ++++++++++++++++++++++
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index b82db7224e..64d9e7bf43 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -206,10 +206,12 @@ public class WideningCategories {
*/
public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) {
ClassNode lub = lowestUpperBound(a, b, null, null);
- if (lub==null || !lub.isUsingGenerics()) return lub;
- // types may be parameterized. If so, we must ensure that generic type arguments
+ if (lub == null || !lub.isUsingGenerics()
+ || lub.isGenericsPlaceHolder()) { // GROOVY-10330
+ return lub;
+ }
+ // types may be parameterized; if so, ensure that generic type arguments
// are made compatible
-
if (lub instanceof LowestUpperBoundClassNode) {
// no parent super class representing both types could be found
// or both class nodes implement common interfaces which may have
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index f09d895c25..2582791dfa 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1164,7 +1164,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
- @NotYetImplemented // GROOVY-10230
+ // GROOVY-10230
void testDiamondInferrenceFromConstructor23() {
assertScript '''
class A {
diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 612b4425d6..063e95a929 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -131,6 +131,28 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10330
+ void testTypeParameterTypeParameter() {
+ assertScript '''
+ class C<T> {
+ T y
+ void m(T x, java.util.function.Function<T, T> f) {
+ assert f.apply(x) == 'foo'
+ }
+ void test(T x, java.util.function.Function<T, T> f) {
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
+ def type = node.getNodeMetaData(INFERRED_TYPE)
+ assert type.isGenericsPlaceHolder()
+ assert type.unresolvedName == 'T'
+ })
+ def z = true ? x : y
+ m(z, f)
+ }
+ }
+ new C<String>().test('FOO', { it.toLowerCase() })
+ '''
+ }
+
// GROOVY-10357
void testAbstractMethodDefault() {
assertScript '''