groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject incubator-groovy git commit: GROOVY-4255: BUG! exception in phase 'class generation' ... SpreadExpression should not be visited here
Date Mon, 01 Jun 2015 13:02:21 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master 24ec32e6a -> 3e8a49a6a


GROOVY-4255: BUG! exception in phase 'class generation' ... SpreadExpression should not be
visited here


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

Branch: refs/heads/master
Commit: 3e8a49a6abe98586c9656544b5a591eabe6b36da
Parents: 24ec32e
Author: Paul King <paulk@asert.com.au>
Authored: Mon Jun 1 23:02:04 2015 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Mon Jun 1 23:02:04 2015 +1000

----------------------------------------------------------------------
 .../groovy/runtime/ScriptBytecodeAdapter.java         |  6 +++++-
 .../groovy/operator/SpreadListOperatorTest.groovy     | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/3e8a49a6/src/main/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java b/src/main/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
index 8579015..d776d63 100644
--- a/src/main/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
+++ b/src/main/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
@@ -788,7 +788,11 @@ public class ScriptBytecodeAdapter {
             } else if (value.getClass().isArray()) {
                 ret.addAll(DefaultTypeTransformation.primitiveArrayToList(value));
             } else {
-                throw new IllegalArgumentException("cannot spread the type " + value.getClass().getName()
+ " with value " + value);
+                String error = "cannot spread the type " + value.getClass().getName() + "
with value " + value;
+                if (value instanceof Map) {
+                    error += ", did you mean to use the spread-map operator instead?";
+                }
+                throw new IllegalArgumentException(error);
             }
             spreadPos++;
         }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/3e8a49a6/src/test/groovy/operator/SpreadListOperatorTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/SpreadListOperatorTest.groovy b/src/test/groovy/operator/SpreadListOperatorTest.groovy
index 1693878..62a1097 100644
--- a/src/test/groovy/operator/SpreadListOperatorTest.groovy
+++ b/src/test/groovy/operator/SpreadListOperatorTest.groovy
@@ -91,6 +91,20 @@ class SpreadListOperatorTest extends GroovyTestCase {
         items = orig.toList()
         items[*1..2, 4] = 'X'
         assert items == ['a', 'X', 'X', 'd', 'X', 'f']
+
+        def message = shouldFail IllegalArgumentException, '''
+            def items = [1, 2, 3, 4]
+            items[*new Date()]
+        '''
+        assert message.contains('cannot spread the type java.util.Date')
+
+        message = shouldFail IllegalArgumentException, '''
+            def items = [1, 2, 3, 4]
+            def map = [a: 1]
+            items[*map]
+        '''
+        assert message.contains('cannot spread the type java.util.LinkedHashMap')
+        assert message.contains('did you mean to use the spread-map operator instead?')
     }
 
     def sum(a, b, c, d) {


Mime
View raw message