[
https://issues.apache.org/jira/browse/GROOVY-8788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17583001#comment-17583001
]
Eric Milles commented on GROOVY-8788:
-------------------------------------
So I can think of a few options to move forward from this point:
1. Add {{getAt(Map,String}} and {{putAt(Map,String,V}} extension methods. This
gets in front of the getProperty/setProperty behavior. But it means
"map['key']" diverges from "map.key". I tried this option in the [previous
PR|https://github.com/apache/groovy/pull/1766]
2. Add special-case logic in STC to select {{getAt(Map,Object)}} for string
argument and map receiver. (same for putAt). This lets type-checker work like
before. But the public property case described above will still be a cast
exception for SC at least.
3. Add type inference logic to STC for left-square-bracket binary expression
with map receiver and String key. This overrides the type information provided
by method selection.
> 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)