groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-7852: Inconsistent checking of final for multi-assignments
Date Fri, 03 Jun 2016 04:19:04 GMT
Repository: groovy
Updated Branches:
  refs/heads/master b57f46df4 -> 0795f3eef


GROOVY-7852: Inconsistent checking of final for multi-assignments


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

Branch: refs/heads/master
Commit: 0795f3eefd5ee9d0952d355098edc50e38639aaa
Parents: b57f46d
Author: paulk <paulk@asert.com.au>
Authored: Thu Jun 2 12:29:42 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Thu Jun 2 12:29:42 2016 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/classgen/FinalVariableAnalyzer.java  | 11 +++++++++--
 .../groovy/classgen/FinalVariableAnalyzerTest.groovy     |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0795f3ee/src/main/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java b/src/main/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java
index 64006c2..dc47387 100644
--- a/src/main/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java
+++ b/src/main/org/codehaus/groovy/classgen/FinalVariableAnalyzer.java
@@ -28,6 +28,7 @@ import org.codehaus.groovy.ast.expr.EmptyExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.PostfixExpression;
 import org.codehaus.groovy.ast.expr.PrefixExpression;
+import org.codehaus.groovy.ast.expr.TupleExpression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.CatchStatement;
@@ -161,9 +162,15 @@ public class FinalVariableAnalyzer extends ClassCodeVisitorSupport {
         if (assignment) {
             if (leftExpression instanceof Variable) {
                 boolean uninitialized =
-                        isDeclaration &&
-                                rightExpression == EmptyExpression.INSTANCE;
+                        isDeclaration && rightExpression == EmptyExpression.INSTANCE;
                 recordAssignment((Variable) leftExpression, isDeclaration, uninitialized,
false, expression);
+            } else if (leftExpression instanceof TupleExpression) {
+                TupleExpression te = (TupleExpression) leftExpression;
+                for (Expression next : te.getExpressions()) {
+                    if (next instanceof Variable) {
+                        recordAssignment((Variable) next, isDeclaration, false, false, next);
+                    }
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/0795f3ee/src/test/org/codehaus/groovy/classgen/FinalVariableAnalyzerTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/FinalVariableAnalyzerTest.groovy b/src/test/org/codehaus/groovy/classgen/FinalVariableAnalyzerTest.groovy
index d5525cf..cd42b84 100644
--- a/src/test/org/codehaus/groovy/classgen/FinalVariableAnalyzerTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/FinalVariableAnalyzerTest.groovy
@@ -77,6 +77,13 @@ class FinalVariableAnalyzerTest extends GroovyTestCase {
         '''
     }
 
+    void testReassignedVarShouldNotBeFinalWhenUsingMultiAssigment() {
+        assertFinals x: false, '''
+            def x = 1
+            (x) = [2]
+        '''
+    }
+
     void testUnassignedVarShouldNotBeConsideredFinal() {
         assertFinals x:false, '''def x'''
     }


Mime
View raw message