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:29 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master 58d4d6a16 -> f6a194fe9


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/f6a194fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/f6a194fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/f6a194fe

Branch: refs/heads/master
Commit: f6a194fe908666396988df4ce7e5e2b305091f31
Parents: 58d4d6a
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:08:57 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/f6a194fe/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 c09e12b..05522de 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3373,6 +3373,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/f6a194fe/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