groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject incubator-groovy git commit: GROOVY-7631: If p is a primitive value, p != null returns false when statically compiled (closes #148)
Date Mon, 19 Oct 2015 16:27:13 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master 9255897e7 -> 78f0b9753


GROOVY-7631: If p is a primitive value, p != null returns false when statically compiled (closes
#148)


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

Branch: refs/heads/master
Commit: 78f0b9753554f926208a6e3ed4a01e092e39af29
Parents: 9255897
Author: Shil S <shil.sinha@gmail.com>
Authored: Sun Oct 18 18:09:05 2015 -0400
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Mon Oct 19 18:26:19 2015 +0200

----------------------------------------------------------------------
 .../sc/transformers/CompareToNullExpression.java    |  2 +-
 .../classgen/asm/sc/BugsStaticCompileTest.groovy    | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/78f0b975/src/main/org/codehaus/groovy/transform/sc/transformers/CompareToNullExpression.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/sc/transformers/CompareToNullExpression.java
b/src/main/org/codehaus/groovy/transform/sc/transformers/CompareToNullExpression.java
index c082031..723be81 100644
--- a/src/main/org/codehaus/groovy/transform/sc/transformers/CompareToNullExpression.java
+++ b/src/main/org/codehaus/groovy/transform/sc/transformers/CompareToNullExpression.java
@@ -62,7 +62,7 @@ public class CompareToNullExpression extends BinaryExpression implements
Opcodes
             ClassNode top = controller.getOperandStack().getTopOperand();
             if (ClassHelper.isPrimitiveType(top)) {
                 controller.getOperandStack().pop();
-                mv.visitInsn(ICONST_0);
+                mv.visitInsn(equalsNull ? ICONST_0 : ICONST_1);
                 controller.getOperandStack().push(ClassHelper.boolean_TYPE);
                 return;
             }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/78f0b975/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 922448e..1e36507 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -1410,5 +1410,21 @@ println someInt
             new A()
         '''
     }
+
+    // GROOVY-7631
+    void testPrimitiveNotEqualNullShouldReturnTrue() {
+        assertScript '''
+            assert false != null
+            assert true != null
+            assert (byte) 1 != null
+            assert (short) 1 != null
+            assert 0 != null
+            assert 1 != null
+            assert 1L != null
+            assert 1f != null
+            assert 1d != null
+            assert (char) 1 != null
+        '''
+    }
 }
 


Mime
View raw message