You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/09/10 15:31:35 UTC

[groovy] branch GROOVY_2_5_X updated: added notes

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

emilles 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 597ec3d7f6 added notes
597ec3d7f6 is described below

commit 597ec3d7f665b4a47cdd63329d5cb22ec4ec3b5c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Sep 10 10:02:56 2022 -0500

    added notes
---
 .../codehaus/groovy/classgen/AsmClassGenerator.java   | 14 +++++++-------
 .../transform/stc/FieldsAndPropertiesSTCTest.groovy   |  4 +++-
 .../sc/FieldsAndPropertiesStaticCompileTest.groovy    | 19 -------------------
 3 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 9d3ced436b..60e560b6c1 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -91,7 +91,6 @@ import org.codehaus.groovy.ast.stmt.SynchronizedStatement;
 import org.codehaus.groovy.ast.stmt.ThrowStatement;
 import org.codehaus.groovy.ast.stmt.TryCatchStatement;
 import org.codehaus.groovy.ast.stmt.WhileStatement;
-import org.codehaus.groovy.ast.tools.GeneralUtils;
 import org.codehaus.groovy.ast.tools.WideningCategories;
 import org.codehaus.groovy.classgen.asm.BytecodeHelper;
 import org.codehaus.groovy.classgen.asm.BytecodeVariable;
@@ -133,6 +132,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.attrX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
 import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.PROPERTY_OWNER;
 
@@ -1249,18 +1249,18 @@ public class AsmClassGenerator extends ClassGenerator {
         }
     }
 
-    private boolean isGroovyObject(Expression objectExpression) {
+    private boolean isGroovyObject(final Expression objectExpression) {
         if (ExpressionUtils.isThisExpression(objectExpression)) return true;
         if (objectExpression instanceof ClassExpression) return false;
 
+        // GROOVY-9195, GROOVY-9288: uniform treatment for "foo.bar" and "foo.with { bar }" using TypeChooser (not getType())
         ClassNode objectExpressionType = controller.getTypeChooser().resolveType(objectExpression, controller.getClassNode());
-        if (objectExpressionType.equals(ClassHelper.OBJECT_TYPE)) objectExpressionType = objectExpression.getType();
-        if (GeneralUtils.isOrImplements(objectExpressionType, ClassHelper.MAP_TYPE)) return false; // GROOVY-8074
-        return implementsGroovyObject(objectExpressionType); // GROOVY-9195, GROOVY-9288, et al.
+        return implementsGroovyObject(objectExpressionType) // GROOVY-10540
+            && !isOrImplements(objectExpressionType, ClassHelper.MAP_TYPE); // GROOVY-5517, GROOVY-8074
     }
 
-    private static boolean implementsGroovyObject(ClassNode cn) {
-        return cn.isDerivedFromGroovyObject() || (!cn.isInterface() && cn.getCompileUnit() != null);
+    private static boolean implementsGroovyObject(final ClassNode cn) {
+        return cn.isDerivedFromGroovyObject() || (cn.getCompileUnit() != null && !cn.isInterface());
     }
 
     public void visitFieldExpression(FieldExpression expression) {
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 8fca6e79fb..7a68af7343 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -507,12 +507,14 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
                 public static int version = 666
             }
             def map = new C()
-            map['foo'] = 123
+            map.foo = 123
             def value = map.foo
             assert value == 123
             map['foo'] = 4.5
             value = map['foo']
             assert value == 4.5
+            value = map.version
+            assert value == null
             assert C.version == 666
         '''
     }
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
index afef3d75e4..0a539eb0fd 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
@@ -22,25 +22,6 @@ import groovy.transform.stc.FieldsAndPropertiesSTCTest
 
 final class FieldsAndPropertiesStaticCompileTest extends FieldsAndPropertiesSTCTest implements StaticCompilationTestSupport {
 
-    void testMapGetAt() {
-        assertScript '''
-            Map map = [a: 1, b:2]
-            String key = 'b'
-            assert map['a'] == 1
-            assert map[key] == 2
-        '''
-    }
-
-    void testGetAtFromStaticMap() {
-        assertScript '''
-            class Foo {
-                public static Map CLASSES = [:]
-            }
-            String foo = 'key'
-            Foo.CLASSES[foo]
-        '''
-    }
-
     // GROOVY-5561
     void testShouldNotThrowAccessForbidden() {
         assertScript '''