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 2306fdd5d8 GROOVY-9391: Cannot cast or coerce `super`
2306fdd5d8 is described below

commit 2306fdd5d8fcb988cd8a9afa197d781dd2e28399
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Mar 29 18:43:32 2025 +0900

    GROOVY-9391: Cannot cast or coerce `super`
---
 .../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 46cb515314..ba7112a9a7 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -2922,7 +2922,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 da50aeac44..9d5b789773 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 'groovy core - Super'() {
         TestUtils.doRunAndShouldFail('fail/Super_01x.groovy')
+        TestUtils.doRunAndShouldFail('fail/Super_02x.groovy')
     }
 
     // GROOVY-9391

Reply via email to