Repository: groovy
Updated Branches:
  refs/heads/master 7d2d6319f -> ee2345816


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/ee234581
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ee234581
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ee234581

Branch: refs/heads/master
Commit: ee2345816f77c110de7e9391299d5afd10affce3
Parents: 7d2d631
Author: Paul King <pa...@asert.com.au>
Authored: Tue Nov 6 23:29:49 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Tue Nov 6 23:30:09 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/ee234581/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/ee234581/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