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 2021/09/19 01:38:19 UTC
[groovy] branch master updated: GROOVY-10243: IOOBE thrown when
parsing switch-expression without branches
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 d0dba39 GROOVY-10243: IOOBE thrown when parsing switch-expression without branches
d0dba39 is described below
commit d0dba394817e127ab63746cd78dea40db3b326c4
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Sep 19 09:37:55 2021 +0800
GROOVY-10243: IOOBE thrown when parsing switch-expression without branches
---
.../org/apache/groovy/parser/antlr4/AstBuilder.java | 4 ++++
src/test-resources/fail/SwitchExpression_10x.groovy | 20 ++++++++++++++++++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 1 +
3 files changed, 25 insertions(+)
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 052dcfd..3294e9b 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1165,6 +1165,10 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
.map(e -> this.visitSwitchBlockStatementExpressionGroup(e))
.collect(Collectors.toList());
+ if (statementInfoList.isEmpty()) {
+ throw createParsingFailedException("`case` or `default` branches are expected", ctx.LBRACE());
+ }
+
Boolean isArrow = statementInfoList.get(0).getV2();
if (!isArrow && statementInfoList.stream().noneMatch(e -> {
Boolean hasYieldOrThrowStatement = e.getV3();
diff --git a/src/test-resources/fail/SwitchExpression_10x.groovy b/src/test-resources/fail/SwitchExpression_10x.groovy
new file mode 100644
index 0000000..0b16554
--- /dev/null
+++ b/src/test-resources/fail/SwitchExpression_10x.groovy
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+println switch (10) {}
diff --git a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 90eab45..0056180 100644
--- a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -442,6 +442,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
TestUtils.doRunAndShouldFail('fail/SwitchExpression_07x.groovy')
TestUtils.doRunAndShouldFail('fail/SwitchExpression_08x.groovy')
TestUtils.doRunAndShouldFail('fail/SwitchExpression_09x.groovy')
+ TestUtils.doRunAndShouldFail('fail/SwitchExpression_10x.groovy')
}
@NotYetImplemented