[
https://issues.apache.org/jira/browse/GROOVY-8788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17582251#comment-17582251
]
Jochen Theodorou commented on GROOVY-8788:
------------------------------------------
Point A is that consistency. The static compiler should behave the same for
extension methods and non extension methods in terms of what extension methods
mean (I made examples above). This is not specific to map of course.
But the trouble here already starts with Point B. From what I gathered
Map<String,?> would convert GString keys to String. But then in case of
Map<?,?> I got from your comment that this is not the case. If GString would
really extend String, then this would not matter, but since it does not extend
it we get a problem that does not exist for example in Java. GString->String is
no cast, it is a conversion. Such exist in Java as widening and as boxing. But
since you cannot use a different key for Map<?,?> than for Map<Integer,?>
boxing does not matter. Potentially there would be a problem with trying to use
an int for Map<?,?> and Map<Long,?>, but I have not checked if that is actually
legal without using any cast. there are also Lambda expressions... but since
they have no specific type on their own the problem does not exist here as well.
I think you can do Point A, Point B+ is a can of worms.
> Inconsistency in extension method selection with @CompileStatic
> ---------------------------------------------------------------
>
> Key: GROOVY-8788
> URL: https://issues.apache.org/jira/browse/GROOVY-8788
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 2.4.15, 2.5.2
> Reporter: Daniil Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
> Labels: breaking
>
> Given properly registered extension class:
> {code:java|title=MyExtensions.java}
> public class MyExtensions {
> public static void foo(Object self, String s) {
> System.out.println("Object#foo(String)");
> }
> public static void foo(String self, Object o) {
> System.out.println("String#foo(Object)");
> }
> }
> {code}
> Run
> {code:java|title=playground.groovy}
> void usageExt() {
> "".foo("") // prints "Object#foo(String)" which is correct
> }
> @groovy.transform.CompileStatic
> void usageExtStatic() {
> "".foo("") // prints "String#foo(Object)" which is questionable
> }
> usageExt()
> usageExtStatic()
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)