You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/11/07 15:39:48 UTC

[groovy] branch master updated: Trivial tweak for renaming field

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e17df3  Trivial tweak for renaming field
9e17df3 is described below

commit 9e17df33b4975b7dec2af480e365ab15d88826be
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 7 23:39:07 2020 +0800

    Trivial tweak for renaming field
---
 .../groovy/ginq/provider/collection/GinqAstWalker.groovy       |  7 +++----
 .../src/spec/test/org/apache/groovy/ginq/GinqTest.groovy       | 10 ++++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
index a14894b..8501730 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
@@ -360,12 +360,11 @@ class GinqAstWalker implements GinqAstVisitor<Expression>, SyntaxErrorReportable
         Expression projectionExpr = selectExpression.getProjectionExpr()
 
         List<Expression> expressionList = ((TupleExpression) projectionExpr).getExpressions()
-        Expression lambdaCode
-        if (expressionList.size() > 1) {
+        Expression lambdaCode = expressionList.get(0)
+        def expressionListSize = expressionList.size()
+        if (expressionListSize > 1 || (expressionListSize == 1 && lambdaCode instanceof CastExpression)) {
             ConstructorCallExpression namedListCtorCallExpression = constructNamedRecordCtorCallExpression(expressionList, MD_SELECT_NAME_LIST)
             lambdaCode = namedListCtorCallExpression
-        } else {
-            lambdaCode = expressionList.get(0)
         }
 
         return callXWithLambda(selectMethodReceiver, "select", dataSourceExpression, lambdaCode)
diff --git a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
index 44f70fb..2afaa70 100644
--- a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
+++ b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
@@ -152,6 +152,16 @@ class GinqTest {
     }
 
     @Test
+    void "testGinq - from select - 8"() {
+        assertScript '''
+            assert [[1], [2], [3]] == GQ {
+                from n in [1, 2, 3]
+                select n as v1
+            }.toList()
+        '''
+    }
+
+    @Test
     void "testGinq - from where select - 1"() {
         assertScript '''
             def numbers = [0, 1, 2, 3, 4, 5]