Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 781f15cc1 -> 43908fa49


GROOVY-8868: Static factory method does not compile anymore with 2.5.3 (was ok 
with 2.4.x)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/43908fa4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/43908fa4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/43908fa4

Branch: refs/heads/GROOVY_2_5_X
Commit: 43908fa4903056301ea531ac08004b217dbb416e
Parents: 781f15c
Author: Paul King <pa...@asert.com.au>
Authored: Tue Nov 6 23:29:49 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Nov 12 22:56:36 2018 +1000

----------------------------------------------------------------------
 .../TupleConstructorASTTransformation.java      |  6 ++++
 src/test/groovy/bugs/Groovy8868Bug.groovy       | 35 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/43908fa4/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
 
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index d421a47..1748eb6 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -39,6 +39,7 @@ import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.EmptyStatement;
+import org.codehaus.groovy.ast.stmt.ExpressionStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
 import org.codehaus.groovy.classgen.VariableScopeVisitor;
 import org.codehaus.groovy.control.CompilationUnit;
@@ -265,6 +266,11 @@ public class TupleConstructorASTTransformation extends 
AbstractASTTransformation
             scopeVisitor.visitClass(cNode);
         }
 
+        // GROOVY-8868 don't want an empty body to cause the constructor to be 
deleted later
+        if (body.isEmpty()) {
+            body.addStatement(new 
ExpressionStatement(ConstantExpression.EMPTY_EXPRESSION));
+        }
+
         // If the first param is def or a Map, named args might not work as 
expected so we add a hard-coded map constructor in this case
         // we don't do it for LinkedHashMap for now (would lead to duplicate 
signature)
         // or if there is only one Map property (for backwards compatibility)

http://git-wip-us.apache.org/repos/asf/groovy/blob/43908fa4/src/test/groovy/bugs/Groovy8868Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8868Bug.groovy 
b/src/test/groovy/bugs/Groovy8868Bug.groovy
new file mode 100644
index 0000000..d30d8a2
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8868Bug.groovy
@@ -0,0 +1,35 @@
+/*
+ *  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 groovy.bugs
+
+class Groovy8868Bug extends GroovyTestCase {
+    void testNoargConstructorIncludedForImmutableWithNoProperties() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            @groovy.transform.Immutable
+            class Foo {
+                static Foo create(){
+                    return new Foo()
+                }
+            }
+
+            assert Foo.create().toString() == 'Foo()'
+        '''
+    }
+}

Reply via email to