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 b063bbd  Tweak the implicit variable for row number
b063bbd is described below

commit b063bbd1feb28ad7b008b1b454810a432c47fb76
Author: Daniel Sun <[email protected]>
AuthorDate: Fri Nov 27 08:20:19 2020 +0800

    Tweak the implicit variable for row number
---
 .../groovy/ginq/provider/collection/GinqAstWalker.groovy       |  4 ++--
 .../src/spec/test/org/apache/groovy/ginq/GinqTest.groovy       | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 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 1588673..ec7336a 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
@@ -411,7 +411,7 @@ class GinqAstWalker implements GinqAstVisitor<Expression>, 
SyntaxErrorReportable
             lambdaCode = namedListCtorCallExpression
         }
 
-        lambdaCode = lambdaCode.transformExpression(new 
ExpressionTransformer() {
+        lambdaCode = ((ListExpression) new 
ListExpression(Collections.singletonList(lambdaCode)).transformExpression(new 
ExpressionTransformer() {
             @Override
             Expression transform(Expression expression) {
                 if (expression instanceof VariableExpression) {
@@ -423,7 +423,7 @@ class GinqAstWalker implements GinqAstVisitor<Expression>, 
SyntaxErrorReportable
 
                 return expression.transformExpression(this)
             }
-        })
+        })).getExpression(0)
 
         def selectMethodCallExpression = 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 136e8b3..141301b 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
@@ -2551,6 +2551,16 @@ class GinqTest {
     }
 
     @Test
+    void "testGinq - row number - 2"() {
+        assertScript '''
+            assert [0, 1, 2] == GQ {
+                from n in [1, 2, 3]
+                select _rn
+            }.toList()
+        '''
+    }
+
+    @Test
     void "testGinq - exists - 1"() {
         assertScript '''
             assert [2, 3] == GQ {

Reply via email to