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/25 23:48:26 UTC

[groovy] branch master updated: Tweak error message for missing `select` clause

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 3a7aad2  Tweak error message for missing `select` clause
3a7aad2 is described below

commit 3a7aad2e71abedb46bcd3709134e27b9e3114c08
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Nov 26 07:48:09 2020 +0800

    Tweak error message for missing `select` clause
---
 .../main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java | 10 +++++++++-
 .../test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy    |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
index 43ff6a4..a214c95 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
@@ -63,6 +63,12 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
     }
 
     public GinqExpression getGinqExpression() {
+        if (null == latestGinqExpression && !ginqExpressionStack.isEmpty()) {
+            GinqExpression latestGinqExpression = ginqExpressionStack.peek();
+            this.collectSyntaxError(new GinqSyntaxError("`select` clause is missing",
+                    latestGinqExpression.getLineNumber(), latestGinqExpression.getColumnNumber()));
+        }
+
         return latestGinqExpression;
     }
 
@@ -87,7 +93,9 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
         if (!KEYWORD_SET.contains(methodName)) return;
 
         if (KW_FROM.equals(methodName)) {
-            ginqExpressionStack.push(new GinqExpression()); // store the result
+            final GinqExpression ginqExpression = new GinqExpression();
+            ginqExpression.setSourcePosition(call);
+            ginqExpressionStack.push(ginqExpression); // store the result
         }
 
         GinqExpression currentGinqExpression = ginqExpressionStack.peek();
diff --git a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
index c93e9d8..1ba7294 100644
--- a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
+++ b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
@@ -33,7 +33,7 @@ class GinqErrorTest {
             }
         '''
 
-        assert err.toString().contains('`select` clause is missing')
+        assert err.toString().contains('`select` clause is missing @ line 2, column 17.')
     }
 
     @Test