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:27:50 UTC

[groovy] branch master updated (b78f595 -> 387c547)

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

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


    from b78f595  Trivial refactoring: Simplify the code further
     new c614d0f  GROOVY-9115: General error during class generation(closes #928)
     new 387c547  Trivial refactoring: Remove redundant condition(closes #927)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/runtime/DefaultGroovyMethods.java       |  6 ++-
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 .../{Groovy8059Bug.groovy => Groovy9115Bug.groovy} | 46 ++++++++++++++--------
 3 files changed, 34 insertions(+), 20 deletions(-)
 copy src/test/groovy/bugs/{Groovy8059Bug.groovy => Groovy9115Bug.groovy} (54%)


[groovy] 02/02: Trivial refactoring: Remove redundant condition(closes #927)

Posted by su...@apache.org.
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 387c54701a6321776fc2aa61b03bb9b8e76b12cc
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat May 11 21:27:12 2019 +0800

    Trivial refactoring: Remove redundant condition(closes #927)
---
 src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index afc3fb4..d4a7479 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -7579,10 +7579,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      *
      * @return a new eager or lazy list of the values at the given indices
      */
+    @SuppressWarnings("unchecked")
     public static <T> List<T> getAt(ListWithDefault<T> self, Collection indices) {
         List<T> answer = ListWithDefault.newInstance(new ArrayList<T>(indices.size()), self.isLazyDefaultValues(), self.getInitClosure());
         for (Object value : indices) {
-            if (value instanceof Range || value instanceof Collection) {
+            if (value instanceof Collection) {
                 answer.addAll((List<T>) InvokerHelper.invokeMethod(self, "getAt", value));
             } else {
                 int idx = normaliseIndex(DefaultTypeTransformation.intUnbox(value), self.size());
@@ -7667,10 +7668,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @return a new list of the values at the given indices
      * @since 1.0
      */
+    @SuppressWarnings("unchecked")
     public static <T> List<T> getAt(List<T> self, Collection indices) {
         List<T> answer = new ArrayList<T>(indices.size());
         for (Object value : indices) {
-            if (value instanceof Range || value instanceof Collection) {
+            if (value instanceof Collection) {
                 answer.addAll((List<T>)InvokerHelper.invokeMethod(self, "getAt", value));
             } else {
                 int idx = DefaultTypeTransformation.intUnbox(value);


[groovy] 01/02: GROOVY-9115: General error during class generation(closes #928)

Posted by su...@apache.org.
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 <su...@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()
+        '''
+    }
+}