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

commit 9dbc51c5e9b4b22ded7e6d0f8ca75ee713417b6f
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Mar 29 16:16:58 2025 +0900

    GROOVY-10240: Compact constructor should have the same name as record
    
    (cherry picked from commit d69299ecfdc8f6c57b74c3ab01455a24b1dfaa52)
---
 .../apache/groovy/parser/antlr4/AstBuilder.java    |  2 +-
 .../fail/RecordDeclaration_17x.groovy              | 25 ++++++++++++++++++++++
 .../groovy/parser/antlr4/SyntaxErrorTest.groovy    |  1 +
 3 files changed, 27 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 38f8780ece..1e9569ddee 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1688,7 +1688,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
         String methodName = this.visitMethodName(ctx.methodName());
         String className = classNode.getNodeMetaData(CLASS_NAME);
         if (!methodName.equals(className)) {
-            createParsingFailedException("Compact constructor should have the 
same name as record: " + className, ctx.methodName());
+            throw createParsingFailedException("Compact constructor should 
have the same name as record: " + className, ctx.methodName());
         }
 
         Parameter[] header = classNode.getNodeMetaData(RECORD_HEADER);
diff --git a/src/test-resources/fail/RecordDeclaration_17x.groovy 
b/src/test-resources/fail/RecordDeclaration_17x.groovy
new file mode 100644
index 0000000000..d9d3f035f8
--- /dev/null
+++ b/src/test-resources/fail/RecordDeclaration_17x.groovy
@@ -0,0 +1,25 @@
+/*
+ *  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.
+ */
+package fail
+
+record Person(String name, int age) {
+    Person2 {
+        // Compact constructor should have the same name as record
+    }
+}
diff --git a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy 
b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 56d93fcb94..c09b5a4da6 100644
--- a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -479,6 +479,7 @@ final class SyntaxErrorTest {
         TestUtils.doRunAndShouldFail('fail/RecordDeclaration_14x.groovy')
         TestUtils.doRunAndShouldFail('fail/RecordDeclaration_15x.groovy')
         TestUtils.doRunAndShouldFail('fail/RecordDeclaration_16x.groovy')
+        TestUtils.doRunAndShouldFail('fail/RecordDeclaration_17x.groovy')
     }
 
     @Test

Reply via email to