groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject incubator-groovy git commit: GROOVY-7639 Comparing primitive to null safe primitive property expression should not throw NPE * Correct assertions in tests for GROOVY-5613 Closes #167
Date Sun, 01 Nov 2015 15:48:47 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X cadbb2b7b -> d2cf2a2fa


GROOVY-7639 Comparing primitive to null safe primitive property expression should not throw
NPE
* Correct assertions in tests for GROOVY-5613
Closes #167


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/d2cf2a2f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/d2cf2a2f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/d2cf2a2f

Branch: refs/heads/GROOVY_2_4_X
Commit: d2cf2a2fa54758efae9241b4ecd4c9878099f406
Parents: cadbb2b
Author: Shil Sinha <shils@apache.org>
Authored: Wed Oct 28 23:58:56 2015 -0400
Committer: Shil Sinha <shils@apache.org>
Committed: Sun Nov 1 10:20:11 2015 -0500

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingVisitor.java |  2 ++
 .../classgen/asm/sc/BugsStaticCompileTest.groovy | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/d2cf2a2f/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 7d86200..ff62df1 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3351,6 +3351,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             cn = getWrapper(cn);
         } else if (exp instanceof MethodCallExpression && ((MethodCallExpression)
exp).isSafe() && isPrimitiveType(cn)) {
             cn = getWrapper(cn);
+        } else if (exp instanceof PropertyExpression && ((PropertyExpression) exp).isSafe()
&& isPrimitiveType(cn)) {
+            cn = getWrapper(cn);
         }
         if (cn == UNKNOWN_PARAMETER_TYPE) {
             // this can happen for example when "null" is used in an assignment or a method
parameter.

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/d2cf2a2f/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 1e36507..617e375 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -259,7 +259,7 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
         }
         A a = new A()
         @ASTTest(phase=INSTRUCTION_SELECTION, value={
-            assert node.getNodeMetaData(INFERRED_TYPE) == int_TYPE
+            assert node.getNodeMetaData(INFERRED_TYPE) == Integer_TYPE
         })
         def x = a?.x
         '''
@@ -272,7 +272,7 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
         }
         A a = new A()
         @ASTTest(phase=INSTRUCTION_SELECTION, value={
-            assert node.getNodeMetaData(INFERRED_TYPE) == long_TYPE
+            assert node.getNodeMetaData(INFERRED_TYPE) == Long_TYPE
         })
         def x = a?.x
         '''
@@ -285,7 +285,7 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
         }
         A a = new A()
         @ASTTest(phase=INSTRUCTION_SELECTION, value={
-            assert node.getNodeMetaData(INFERRED_TYPE) == char_TYPE
+            assert node.getNodeMetaData(INFERRED_TYPE) == Character_TYPE
         })
         def x = a?.x
         assert x == 'a'
@@ -1426,5 +1426,18 @@ println someInt
             assert (char) 1 != null
         '''
     }
+
+    // GROOVY-7639
+    void testComparisonOfPrimitiveWithNullSafePrimitivePropertyExpression() {
+        assertScript '''
+            class Foo {
+                int bar
+            }
+            Foo foo = null
+            assert !(foo?.bar == 7)
+            assert !(foo?.bar > 7)
+            assert foo?.bar < 7
+        '''
+    }
 }
 


Mime
View raw message