Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 269c0c8a0 -> d319b8a18


Groovy-7291: reenable tests and fix the fix for indy as well


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

Branch: refs/heads/GROOVY_2_4_X
Commit: d319b8a18a53555308286719a6fdb890a5a7dd30
Parents: 269c0c8
Author: Jochen Theodorou <blackd...@gmx.org>
Authored: Sun Oct 16 15:59:50 2016 +0200
Committer: Jochen Theodorou <blackd...@gmx.org>
Committed: Sun Oct 16 16:02:47 2016 +0200

----------------------------------------------------------------------
 .../groovy/classgen/AsmClassGenerator.java      |  6 ++++-
 .../groovy/classgen/asm/CompileStack.java       | 15 ++++++++---
 .../classgen/asm/OptimizingStatementWriter.java | 28 ++++----------------
 src/test/groovy/bugs/Groovy7291Bug.groovy       | 21 +--------------
 4 files changed, 22 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d319b8a1/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java 
b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 3d30e20..e1d17da 100644
--- a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -388,7 +388,11 @@ public class AsmClassGenerator extends ClassGenerator {
             }
             // we use this NOP to have a valid jump target for the various 
labels
             //mv.visitInsn(NOP);
-            mv.visitMaxs(0, 0);
+            try {
+                mv.visitMaxs(0, 0);
+            } catch (Exception e) {
+                throw new GroovyRuntimeException("ASM reporting processing 
error for "+controller.getClassNode()+"#"+node.getName()+" with signature 
"+node.getTypeDescriptor()+" in "+sourceFile+":"+node.getLineNumber(), e);
+            }
         }
         mv.visitEnd();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d319b8a1/src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/CompileStack.java 
b/src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
index edd37d5..0c98fd6 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
@@ -658,10 +658,8 @@ public class CompileStack implements Opcodes {
     public BytecodeVariable defineVariable(Variable v, boolean initFromStack) {
         return defineVariable(v, v.getOriginType(), initFromStack);
     }
+
     public BytecodeVariable defineVariable(Variable v, ClassNode variableType, 
boolean initFromStack) {
-        //TODO: any usage of this method should have different operand stack 
handing
-        //      then the remove(1) here and there in this one can be removed 
and others
-        //      can be changed
         String name = v.getName();
         BytecodeVariable answer = defineVar(name, variableType, 
v.isClosureSharedVariable(), v.isClosureSharedVariable());
         stackVariables.put(name, answer);
@@ -672,7 +670,16 @@ public class CompileStack implements Opcodes {
         ClassNode type = answer.getType().redirect();
         OperandStack operandStack = controller.getOperandStack();
 
-        if (!initFromStack) pushInitValue(type, mv);
+        if (!initFromStack) {
+            if (ClassHelper.isPrimitiveType(v.getOriginType()) && 
ClassHelper.getWrapper(v.getOriginType()) == variableType) {
+                pushInitValue(v.getOriginType(), mv);
+                operandStack.push(v.getOriginType());
+                operandStack.box();
+                operandStack.remove(1);
+            } else {
+                pushInitValue(type, mv);
+            }
+        }
         operandStack.push(answer.getType());
         if (answer.isHolder())  {
             operandStack.box();

http://git-wip-us.apache.org/repos/asf/groovy/blob/d319b8a1/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java 
b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
index e72b112..17a9810 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
@@ -581,37 +581,19 @@ public class OptimizingStatementWriter extends 
StatementWriter {
             addTypeInformation(expression.getExpression(),expression);
         }
 
-        private void 
replaceEmptyToConstantZeroIfNecessary(DeclarationExpression expression) {
-            // GROOVY-7291 and GROOVY-5570, a variable referenced by closure 
cannot be primitive type
-            // So here's a trick: in this case replace EmptyExpression on the 
right side to a ConstantExpression
-            Expression leftExpression = expression.getLeftExpression();
-            Expression rightExpression=expression.getRightExpression();
-            if (leftExpression instanceof VariableExpression
-                    && rightExpression instanceof EmptyExpression) {
-                VariableExpression leftVariableExpression = 
(VariableExpression) leftExpression;
-
-                if (isPrimitiveType(leftVariableExpression.getOriginType())
-                        && leftVariableExpression.isClosureSharedVariable()) {
-                   expression.setRightExpression(new ConstantExpression(0));
-                }
-            }
-        }
-
         @Override
         public void visitDeclarationExpression(DeclarationExpression 
expression) {
-            replaceEmptyToConstantZeroIfNecessary(expression);
-
-            Expression rightExpression = expression.getRightExpression();
-            rightExpression.visit(this);
+            Expression right = expression.getRightExpression();
+            right.visit(this);
 
             ClassNode leftType = 
typeChooser.resolveType(expression.getLeftExpression(), node);
+            Expression rightExpression = expression.getRightExpression();
             ClassNode rightType = 
optimizeDivWithIntOrLongTarget(rightExpression, leftType);
-
-            if (rightType==null) rightType = 
typeChooser.resolveType(rightExpression, node);
+            if (rightType==null) rightType = 
typeChooser.resolveType(expression.getRightExpression(), node);
             if (isPrimitiveType(leftType) && isPrimitiveType(rightType)) {
                 // if right is a constant, then we optimize only if it makes
                 // a block complete, so we set a maybe
-                if (rightExpression instanceof ConstantExpression) {
+                if (right instanceof ConstantExpression) {
                     opt.chainCanOptimize(true);
                 } else {
                     opt.chainShouldOptimize(true);

http://git-wip-us.apache.org/repos/asf/groovy/blob/d319b8a1/src/test/groovy/bugs/Groovy7291Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7291Bug.groovy 
b/src/test/groovy/bugs/Groovy7291Bug.groovy
index 1e83f81..22203d0 100644
--- a/src/test/groovy/bugs/Groovy7291Bug.groovy
+++ b/src/test/groovy/bugs/Groovy7291Bug.groovy
@@ -18,32 +18,13 @@
  */
 package groovy.bugs
 
-import groovy.transform.NotYetImplemented
-
 class Groovy7291Bug extends GroovyTestCase {
 
-    static final boolean runningWithIndy = 
Boolean.getBoolean('groovy.target.indy')
-
-    @NotYetImplemented
-    void testPrimitiveDoubleIndy() {
-        if (!runningWithIndy) return
-        assertScript '''
-            double a
-            def b = {
-               a = a + 1
-            }
-            b()
-            assert a == 1.0d
-        '''
-    }
-
     void testPrimitiveDouble() {
-        // TODO: remove this conditional and method above when fixed for Indy
-        if (runningWithIndy) return
-
         assertScript '''
             double a
             def b = {
+               assert a.class == Double
                a = a + 1
             }
             b()

Reply via email to