You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/06/01 14:44:27 UTC

incubator-groovy git commit: GROOVY-4787: BUG! exception in phase 'class generation' generating class from map in closure (closes #30)

Repository: incubator-groovy
Updated Branches:
  refs/heads/master f0bf0c867 -> 24ec32e6a


GROOVY-4787: BUG! exception in phase 'class generation' generating class from map in closure (closes #30)


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

Branch: refs/heads/master
Commit: 24ec32e6a5cfb653f9ca8aa151bbf6a671905098
Parents: f0bf0c8
Author: Paul King <pa...@asert.com.au>
Authored: Mon Jun 1 22:42:37 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Jun 1 22:43:13 2015 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java |  7 ++++
 .../operator/SpreadMapOperatorTest.groovy       | 34 ++++++++++++++------
 2 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/24ec32e6/src/main/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/org/codehaus/groovy/control/ResolveVisitor.java
index 302207c..c0f6f2b 100644
--- a/src/main/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1002,6 +1002,13 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                         return ce;
                     }
                 }
+            } else if (be.getRightExpression() instanceof SpreadMapExpression) {
+                // we have C[*:map] -> should become (C) map
+                SpreadMapExpression mapExpression = (SpreadMapExpression) be.getRightExpression();
+                Expression right = transform(mapExpression.getExpression());
+                Expression ce = new CastExpression(left.getType(), right);
+                ce.setSourcePosition(be);
+                return ce;
             }
 
             if (be.getRightExpression() instanceof MapEntryExpression) {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/24ec32e6/src/test/groovy/operator/SpreadMapOperatorTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/SpreadMapOperatorTest.groovy b/src/test/groovy/operator/SpreadMapOperatorTest.groovy
index 97a54ff..f455879 100644
--- a/src/test/groovy/operator/SpreadMapOperatorTest.groovy
+++ b/src/test/groovy/operator/SpreadMapOperatorTest.groovy
@@ -32,7 +32,6 @@ package groovy.operator
  *            assert z == w
  *
  * @author Pilho Kim
- * @version $Revision$
  */
 
 public class SpreadMapOperatorTest extends GroovyTestCase {
@@ -100,17 +99,34 @@ public class SpreadMapOperatorTest extends GroovyTestCase {
         assert w == w2
     }
 
+    void testSpecialSpreadMapIndexNotation() {
+        assertScript '''
+        @groovy.transform.ToString
+        class Person { String name; int age }
+
+        assert Person[ name:'Dave', age:32 ].toString() == 'Person(Dave, 32)'
+
+        def timMap = [ name:'Tim', age:49 ]
+        assert Person[ *:timMap ].toString() == 'Person(Tim, 49)'
+
+        assert Person[ *:[ name:'John', age:29 ] ].toString() == 'Person(John, 29)'
+
+        def ppl = [ [ name:'Tim', age:49 ], [ name:'Dave', age:32 ], [ name:'Steve', age:18 ] ]
+        assert ppl.collect { Person [ *:it ] }*.age == [49, 32, 18]
+        '''
+    }
+
     void testSpreadMapFunctionCall() {
-             def m = ['a':10, 'b':20, 'c':30]
-             f(*:m)                 // Call with only one spread map argument
-             f(*:m, 'e':50)      // Call with one spread map argument and one named argument
-             f('e':100, *:m)     // Call with one named argument and one spread map argument
+         def m = ['a':10, 'b':20, 'c':30]
+         f(*:m)                 // Call with only one spread map argument
+         f(*:m, 'e':50)      // Call with one spread map argument and one named argument
+         f('e':100, *:m)     // Call with one named argument and one spread map argument
 
-             func('e':100, 1, 2, 3, *:m)       // Call with one named argument, three usual arguments,  and one spread map argument
+         func('e':100, 1, 2, 3, *:m)       // Call with one named argument, three usual arguments,  and one spread map argument
 
-             def l = [4, 5]
-             func('e':100, *l, *:m, 6)       // Call with one named argument, one spread list argument, one spread map argument, and  one usual argument
-             func(7, 'e':100, *l, *:m)       // Call with one usual argument, one named argument, one spread list argument, and one spread map argument 
+         def l = [4, 5]
+         func('e':100, *l, *:m, 6)       // Call with one named argument, one spread list argument, one spread map argument, and  one usual argument
+         func(7, 'e':100, *l, *:m)       // Call with one usual argument, one named argument, one spread list argument, and one spread map argument
     }
 }