This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 736177f367 GROOVY-9391: Cannot cast or coerce `super`
736177f367 is described below
commit 736177f36764d0afa767382987f51511119a5a29
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Mar 29 18:43:32 2025 +0900
GROOVY-9391: Cannot cast or coerce `super`
(cherry picked from commit 2306fdd5d8fcb988cd8a9afa197d781dd2e28399)
---
.../apache/groovy/parser/antlr4/AstBuilder.java | 2 +-
src/test-resources/fail/Super_02x.groovy | 23 ++++++++++++++++++++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 1 +
3 files changed, 25 insertions(+), 1 deletion(-)
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 8fa6fa74c4..3f8f362b32 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -2961,7 +2961,7 @@ public class AstBuilder extends
GroovyParserBaseVisitor<Object> {
public CastExpression visitCastExprAlt(final CastExprAltContext ctx) {
Expression expr = (Expression) this.visit(ctx.expression());
if (expr instanceof VariableExpression && ((VariableExpression)
expr).isSuperExpression()) {
- this.createParsingFailedException("Cannot cast or coerce `super`",
ctx); // GROOVY-9391
+ throw this.createParsingFailedException("Cannot cast or coerce
`super`", ctx); // GROOVY-9391
}
CastExpression cast = new
CastExpression(this.visitCastParExpression(ctx.castParExpression()), expr);
return configureAST(cast, ctx);
diff --git a/src/test-resources/fail/Super_02x.groovy
b/src/test-resources/fail/Super_02x.groovy
new file mode 100644
index 0000000000..cccb3e75a0
--- /dev/null
+++ b/src/test-resources/fail/Super_02x.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+class A {
+ A() {
+ (Object) super
+ }
+}
diff --git a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 59f1157147..68a7f5497d 100644
--- a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -151,6 +151,7 @@ final class SyntaxErrorTest {
@Test
void 'test groovy core - Super'() {
TestUtils.doRunAndShouldFail('fail/Super_01x.groovy')
+ TestUtils.doRunAndShouldFail('fail/Super_02x.groovy')
}
@Test // GROOVY-9391