You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/10/23 03:24:24 UTC
(groovy) branch GROOVY_4_0_X updated: GROOVY-12451: A record with a boolean component x and a hand-written isX() gets no x() accessor
This is an automated email from the ASF dual-hosted git repository.
paulk-asert 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 23eeb11246 GROOVY-12451: A record with a boolean component x and a hand-written isX() gets no x() accessor
23eeb11246 is described below
commit 23eeb11246ff1a4511fb48aa62b64222254c8c20
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Oct 15 13:11:06 2026 +1000
GROOVY-12451: A record with a boolean component x and a hand-written isX() gets no x() accessor
---
.../org/codehaus/groovy/classgen/Verifier.java | 2 +-
src/test/groovy/bugs/Groovy12451.groovy | 86 ++++++++++++++++++++++
2 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index b79b0f4bcc..7b5836f8fd 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -796,7 +796,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
Statement getterBlock = node.getGetterBlock();
if (getterBlock == null && !node.isPrivate()) {
MethodNode getter = classNode.getGetterMethod(getterName, !node.isStatic());
- if (getter == null && isPrimitiveBoolean(node.getType())) {
+ if (getter == null && node.getGetterName() == null && isPrimitiveBoolean(node.getType())) {
getter = classNode.getGetterMethod("is" + capitalize(name), !node.isStatic());
}
if (methodNeedsReplacement(getter)) {
diff --git a/src/test/groovy/bugs/Groovy12451.groovy b/src/test/groovy/bugs/Groovy12451.groovy
new file mode 100644
index 0000000000..acb0516e12
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy12451.groovy
@@ -0,0 +1,86 @@
+/*
+ * 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 bugs
+
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+/**
+ * A hand-written {@code isX()} in a record with a primitive {@code boolean}
+ * component {@code x} was taken as the component's accessor, so no {@code x()}
+ * accessor was generated.
+ */
+final class Groovy12451 {
+
+ @Test
+ void testAccessorGeneratedAlongsideIsser() {
+ assertScript '''
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ record S8(boolean done) {
+ boolean isDone() { done }
+ }
+
+ @CompileStatic
+ class M8 {
+ static boolean check() { new S8(true).done() }
+ }
+
+ assert M8.check()
+ assert S8.recordComponents*.accessor*.name == ['done']
+ '''
+ }
+
+ @Test
+ void testGeneratedRecordMethodsUseAccessor() {
+ assertScript '''
+ record R(boolean done, boolean other) {
+ boolean isDone() { !done }
+ }
+
+ def r = new R(true, false)
+ assert r.done()
+ assert !r.isDone()
+ assert r.toList() == [true, false]
+ assert r.toMap() == [done: true, other: false]
+ assert r[0]
+ assert R.declaredMethods.count { it.name == 'isDone' } == 1
+ '''
+ }
+
+ @Test
+ void testEmulatedRecord() {
+ assertScript '''
+ import groovy.transform.RecordOptions
+ import groovy.transform.RecordTypeMode
+
+ @RecordOptions(mode=RecordTypeMode.EMULATE)
+ record R(boolean done) {
+ boolean isDone() { !done }
+ }
+
+ def r = new R(true)
+ assert r.done()
+ assert !r.isDone()
+ assert r.toList() == [true]
+ '''
+ }
+}