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 2020/05/01 23:54:19 UTC

[groovy] branch GROOVY-9529 created (now 9969e1e)

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

emilles pushed a change to branch GROOVY-9529
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 9969e1e  GROOVY-9529: bump Object in distance calculation to match interface DGM

This branch includes the following new commits:

     new 9969e1e  GROOVY-9529: bump Object in distance calculation to match interface DGM

The 1 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.



[groovy] 01/01: GROOVY-9529: bump Object in distance calculation to match interface DGM

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9529
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9969e1ea794e1fa6e6e293472b55842d1bb27ad6
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
---
 .../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()
+        '''
+    }
 }