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/02/29 07:06:37 UTC
[groovy] 02/03: GROOVY-9420: Incorrect type inference on map[key]
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
commit da145291941cba2e4b153d69217e8106a4fe9994
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Feb 25 23:20:27 2020 +1000
GROOVY-9420: Incorrect type inference on map[key]
(cherry picked from commit aa7ea88fdad19eb0ed95b10bae584582e5ad8665)
---
.../groovy/runtime/DefaultGroovyMethods.java | 2 +-
src/test/groovy/bugs/Groovy9420.groovy | 40 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 9d1f4e9..29ccea2 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -8414,7 +8414,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @return the value corresponding to the given key
* @since 1.0
*/
- public static <K,V> V getAt(Map<K,V> self, K key) {
+ public static <K,V> V getAt(Map<K,V> self, Object key) {
return self.get(key);
}
diff --git a/src/test/groovy/bugs/Groovy9420.groovy b/src/test/groovy/bugs/Groovy9420.groovy
new file mode 100644
index 0000000..51e3bbf
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9420.groovy
@@ -0,0 +1,40 @@
+/*
+ * 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 Groovy9420 extends CompilableTestSupport {
+ void testStaticBooleanIsPropertyInStaticContext() {
+ shouldCompile """
+ @groovy.transform.CompileStatic
+ void blah() {
+ Map<String, String> m = [foo: 'foo']
+ def a = m.get(key)
+ uhuh(a)
+ def b = m[key]
+ uhuh(b)
+ }
+
+ void uhuh(String a) { }
+
+ Object getKey() { 'foo' }
+ """
+ }
+}