groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/02: GROOVY-9115: General error during class generation(closes #928)
Date Sat, 11 May 2019 13:27:51 GMT
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

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

    GROOVY-9115: General error during class generation(closes #928)
---
 .../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 16cb5a8..6210a60 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1702,7 +1702,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()
+        '''
+    }
+}


Mime
View raw message