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 9a642c9  GROOVY-10225: STC: fix for NPE
9a642c9 is described below

commit 9a642c928fbf5dc430dbe2c67357a26033b12c55
Author: Eric Milles <[email protected]>
AuthorDate: Mon Sep 27 16:48:49 2021 -0500

    GROOVY-10225: STC: fix for NPE
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java    |  2 +-
 src/test/groovy/transform/stc/GenericsSTCTest.groovy       | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

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 a92d25b..d000776 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5410,7 +5410,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                 actuals[i] = getLiteralResultType(pt, at, LinkedHashMap_TYPE);
             } else if (a instanceof ConstructorCallExpression) {
                 inferDiamondType((ConstructorCallExpression) a, pt); // 
GROOVY-10086
-            } else if (a instanceof TernaryExpression && at.isUsingGenerics() 
&& at.getGenericsTypes().length == 0) {
+            } else if (a instanceof TernaryExpression && at.getGenericsTypes() 
!= null && at.getGenericsTypes().length == 0) {
                 // GROOVY-9983: double diamond scenario -- "m(flag ? new 
Type<>(...) : new Type<>(...))"
                 
typeCheckingContext.pushEnclosingBinaryExpression(assignX(varX(p), a, a));
                 a.visit(this); // re-visit with target type witness
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy 
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 22001e2..5a8e324 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1640,6 +1640,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase 
{
         'Cannot assign value of type java.lang.String to variable of type 
java.lang.Number'
     }
 
+    // GROOVY-10225
+    void testShouldUseMethodGenericType13() {
+        assertScript '''
+            def <T> T m(T t) {
+                assert t == null
+            }
+            def <N extends Number, X extends N> void test() {
+                X x = (X) null
+                m(false ? x : (X) null) // was NPE
+            }
+            test()
+        '''
+    }
+
     // GROOVY-5516
     void testAddAllWithCollectionShouldBeAllowed() {
         assertScript '''import 
org.codehaus.groovy.transform.stc.ExtensionMethodNode

Reply via email to