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 2020/05/05 23:32:31 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9529: bump Object in distance calculation to match interface DGM

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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new fd26152  GROOVY-9529: bump Object in distance calculation to match interface DGM
fd26152 is described below

commit fd26152c06156864cfbd9f1dd3912fdca48e0235
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri May 1 18:34:55 2020 -0500

    GROOVY-9529: bump Object in distance calculation to match interface DGM
    
    (cherry picked from commit fba3ff43a1ab87d9a5c4ec0b17c367f8786edeb7)
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  3 +-
 src/test/groovy/bugs/Groovy9420.groovy             | 50 ------------------
 .../stc/DefaultGroovyMethodsSTCTest.groovy         | 61 +++++++++++++++++++---
 3 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 7f68533..959f7a3 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -925,7 +925,8 @@ public abstract class StaticTypeCheckingSupport {
             }
             ref = ref.getSuperClass();
             dist += 1;
-            if (ref == null) dist += 1;
+            if (OBJECT_TYPE.equals(ref))
+                dist += 1;
             dist = (dist + 1) << 1;
         }
         return dist;
diff --git a/src/test/groovy/bugs/Groovy9420.groovy b/src/test/groovy/bugs/Groovy9420.groovy
deleted file mode 100644
index ff49f51..0000000
--- a/src/test/groovy/bugs/Groovy9420.groovy
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *  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 groovy.transform.CompileStatic
-import org.junit.Test
-
-import static groovy.test.GroovyAssert.assertScript
-
-@CompileStatic
-final class Groovy9420 {
-
-    @Test
-    void testMapGetVsGetAt() {
-        assertScript '''
-            @groovy.transform.CompileStatic
-            void blah() {
-                Map<String, String> m = [foo: 'bar']
-                def a = m.get(key)
-                test(a)
-                def b = m[key]
-                test(b)
-            }
-
-            Object getKey() { 'foo' }
-
-            void test(String a) {
-                assert a == 'bar'
-            }
-
-            blah()
-        '''
-    }
-}
diff --git a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
index 81eb450..bf36366 100644
--- a/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy
@@ -66,12 +66,12 @@ class DefaultGroovyMethodsSTCTest extends StaticTypeCheckingTestCase {
             true.equals { it }
         '''
     }
-  
+
     void testShouldAcceptMethodFromDefaultDateMethods() {
       assertScript '''
-        def s = new Date()
-        println s.year
-        println s.format("yyyyMMdd")
+          def s = new Date()
+          println s.year
+          println s.format("yyyyMMdd")
       '''
     }
 
@@ -88,7 +88,8 @@ class DefaultGroovyMethodsSTCTest extends StaticTypeCheckingTestCase {
 
     // GROOVY-5584
     void testEachOnMap() {
-        assertScript '''import org.codehaus.groovy.transform.stc.ExtensionMethodNode
+        assertScript '''
+            import org.codehaus.groovy.transform.stc.ExtensionMethodNode
             import org.codehaus.groovy.runtime.DefaultGroovyMethods
 
             @ASTTest(phase=INSTRUCTION_SELECTION, value= {
@@ -195,10 +196,58 @@ class DefaultGroovyMethodsSTCTest extends StaticTypeCheckingTestCase {
                 def results = [:]
                 Functions.values().eachWithIndex { val, idx -> results[idx] = val.name() }
                 results
-            } 
+            }
             assert m() == ['A', 'B', 'C']
             assert m2() == [0: 'A', 1: 'B', 2: 'C']
         '''
     }
 
+    // GROOVY-9420
+    void testMapGetVsGetAt() {
+        assertScript '''
+            void check(String val) {
+                assert val == 'bar'
+            }
+
+            Object getKey() {
+                return 'foo'
+            }
+
+            void test() {
+                Map<String, String> map = [foo: 'bar']
+
+                def one = map.get(key)
+                check(one)
+
+                def two = map[key]
+                check(two)
+            }
+
+            test()
+        '''
+    }
+
+    // GROOVY-9529
+    void testMapGetAtVsObjectGetAt() {
+        assertScript '''
+            interface X extends Map<Object, Object> {}
+
+            interface Y extends X {}
+
+            class C extends HashMap<Object, Object> implements Y {}
+
+            Y newMap() {
+                new C().tap {
+                    put('foo', 'bar')
+                }
+            }
+
+            void test() {
+                def map = newMap()
+                assert map['foo'] == 'bar'
+            }
+
+            test()
+        '''
+    }
 }