This is an automated email from the ASF dual-hosted git repository.
paulk 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 0740b14 GROOVY-10240: Support record grammar (detect invalid abstract
modifier)
0740b14 is described below
commit 0740b141784415814d3038126756219c045db7f3
Author: Paul King <[email protected]>
AuthorDate: Mon Sep 27 00:54:09 2021 +1000
GROOVY-10240: Support record grammar (detect invalid abstract modifier)
---
.../java/org/codehaus/groovy/classgen/Verifier.java | 3 +++
.../fail/RecordDeclaration_12x.groovy | 21 +++++++++++++++++++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 1 +
3 files changed, 25 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index a702223..9a925db 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -228,6 +228,9 @@ public class Verifier implements GroovyClassVisitor,
Opcodes {
if (node.isRecord()) {
detectInvalidRecordComponentNames(node);
+ if (node.isAbstract()) {
+ throw new RuntimeParserException("Record '" +
classNode.getNameWithoutPackage() + "' must not be abstract", classNode);
+ }
}
if (Traits.isTrait(node) // maybe possible to have this true in joint
compilation mode
|| classNode.isInterface()) {
diff --git a/src/test-resources/fail/RecordDeclaration_12x.groovy
b/src/test-resources/fail/RecordDeclaration_12x.groovy
new file mode 100644
index 0000000..90e0e6e
--- /dev/null
+++ b/src/test-resources/fail/RecordDeclaration_12x.groovy
@@ -0,0 +1,21 @@
+/*
+ * 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 core
+
+abstract record Bad(int x) { }
diff --git a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 1f3ad7c..bfac665 100644
--- a/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -444,6 +444,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
TestUtils.doRunAndShouldFail('fail/RecordDeclaration_09x.groovy')
TestUtils.doRunAndShouldFail('fail/RecordDeclaration_10x.groovy')
TestUtils.doRunAndShouldFail('fail/RecordDeclaration_11x.groovy')
+ TestUtils.doRunAndShouldFail('fail/RecordDeclaration_12x.groovy')
}
void 'test groovy core - Array'() {