Repository: groovy
Updated Branches:
  refs/heads/master a2565bebb -> 99f40916f


GROOVY-7841: Assert fails when accessing particular primitive values with 
@CompileStatic


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

Branch: refs/heads/master
Commit: 99f40916ffdc4d3a049cd9ae7fb37f34b8503cbb
Parents: a2565be
Author: paulk <pa...@asert.com.au>
Authored: Tue May 24 21:52:12 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Wed May 25 20:33:59 2016 +1000

----------------------------------------------------------------------
 .../sc/transformers/BooleanExpressionTransformer.java    | 10 +++++++---
 .../groovy/classgen/asm/sc/BugsStaticCompileTest.groovy  | 11 +++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/99f40916/src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
 
b/src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
index 4a81aa5..e60c2cb 100644
--- 
a/src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
+++ 
b/src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java
@@ -134,15 +134,19 @@ public class BooleanExpressionTransformer {
                             // int on stack
                         } else if (top.equals(ClassHelper.long_TYPE)) {
                             MethodVisitor mv = controller.getMethodVisitor();
-                            mv.visitInsn(L2I);
+                            mv.visitInsn(LCONST_0);
+                            mv.visitInsn(LCMP);
                             
controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                         } else if (top.equals(ClassHelper.float_TYPE)) {
                             MethodVisitor mv = controller.getMethodVisitor();
-                            mv.visitInsn(F2I);
+                            mv.visitInsn(F2D);
+                            mv.visitInsn(DCONST_0);
+                            mv.visitInsn(DCMPG);
                             
controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                         } else if (top.equals(ClassHelper.double_TYPE)) {
                             MethodVisitor mv = controller.getMethodVisitor();
-                            mv.visitInsn(D2I);
+                            mv.visitInsn(DCONST_0);
+                            mv.visitInsn(DCMPG);
                             
controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                         }
                         return;

http://git-wip-us.apache.org/repos/asf/groovy/blob/99f40916/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 617e375..b0fd07f 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -22,8 +22,6 @@ import groovy.transform.stc.BugsSTCTest
 
 /**
  * Unit tests for static type checking : bugs.
- *
- * @author Cedric Champeau
  */
 class BugsStaticCompileTest extends BugsSTCTest implements 
StaticCompilationTestSupport {
 
@@ -1439,5 +1437,14 @@ println someInt
             assert foo?.bar < 7
         '''
     }
+
+    // GROOVY-7841
+    void testAssertionOfNonZeroPrimitiveEdgeCases() {
+        assertScript '''
+            assert 4294967296
+            assert 0.1f
+            assert 0.1d
+        '''
+    }
 }
 

Reply via email to