You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2023/04/15 18:28:32 UTC

[groovy] branch master updated: GROOVY-10305: Groovy records do not allow creating non-compact constructors with signature matching the record one

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 57d770dda7 GROOVY-10305: Groovy records do not allow creating non-compact constructors with signature matching the record one
57d770dda7 is described below

commit 57d770dda731b57018c1641bc807ac1e2a42738e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Apr 16 01:43:31 2023 +0800

    GROOVY-10305: Groovy records do not allow creating non-compact constructors with signature matching the record one
---
 src/test/groovy/bugs/Groovy10305.groovy | 55 +++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/test/groovy/bugs/Groovy10305.groovy b/src/test/groovy/bugs/Groovy10305.groovy
new file mode 100644
index 0000000000..db2a9b5d25
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10305.groovy
@@ -0,0 +1,55 @@
+/*
+ *  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.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy10305 {
+
+    @Test
+    void test() {
+        assertScript '''
+            record X(int a) {
+                public X(int a) {
+                    this.a = a
+                }
+            }
+
+            def x = new X(10)
+            assert 10 == x.a()
+        '''
+    }
+
+    @Test
+    void testCS() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            record X(int a) {
+                public X(int a) {
+                    this.a = a
+                }
+            }
+
+            def x = new X(10)
+            assert 10 == x.a()
+        '''
+    }
+}