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 2019/05/11 13:29:20 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-9115: General error during class generation(closes #928)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 9759d54  GROOVY-9115: General error during class generation(closes #928)
9759d54 is described below

commit 9759d543944c67b0f06eb94c246f7112ef7666f5
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat May 11 21:24:54 2019 +0800

    GROOVY-9115: General error during class generation(closes #928)
    
    (cherry picked from commit c614d0f29b30488a0429d51b41627c3f77b83abd)
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 src/test/groovy/bugs/Groovy9115Bug.groovy          | 59 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 2eade00..f855239 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1597,7 +1597,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                         }
                         ClassNode cn = inferReturnTypeGenerics(dgmReceiver, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
                         storeInferredTypeForPropertyExpression(pexp, cn);
-                        storeTargetMethod(pexp, getter);
+                        if (readMode) storeTargetMethod(pexp, getter);
                         return true;
                     }
                 }
diff --git a/src/test/groovy/bugs/Groovy9115Bug.groovy b/src/test/groovy/bugs/Groovy9115Bug.groovy
new file mode 100644
index 0000000..0c7026c
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9115Bug.groovy
@@ -0,0 +1,59 @@
+/*
+ *  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
+
+import gls.CompilableTestSupport
+
+class Groovy9115Bug extends CompilableTestSupport {
+    void testSetPropertyInIfStmt() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        class Derived {
+            def m() {
+                if (true) {
+                    File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
+                    file.text = 'Groovy9115Bug'
+                    assert 'Groovy9115Bug' == file.text
+                }
+                
+                return null
+            }
+        }
+        
+        new Derived().m()
+        '''
+    }
+
+    void testSetProperty() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        class Derived {
+            def m() {
+                File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
+                file.text = 'Groovy9115Bug'
+                assert 'Groovy9115Bug' == file.text
+                
+                return null
+            }
+        }
+        
+        new Derived().m()
+        '''
+    }
+}