[
https://issues.apache.org/jira/browse/GROOVY-6668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17584297#comment-17584297
]
ASF GitHub Bot commented on GROOVY-6668:
----------------------------------------
eric-milles opened a new pull request, #1770:
URL: https://github.com/apache/groovy/pull/1770
Here is the more controversial change of
https://github.com/apache/groovy/pull/1766 so it can be debated/evaluated in
isolation.
A small change in `StaticTypeCheckingSupport#getDistance` can resolve the
`map["$key"]` issues. I know Cedric stated in 6668 that this should be an STC
error, but if there is just one method and it accepts String, it will be chosen
for a GString argument. This change just closes the distance between GString
and String so that `m(String)` is selected over `m(Object)`. Yes, this puts
`Map#get` and `Map#getAt` out of alignment for GString arguments, which was a
stated concern. But the gain is in alignment of dynamic and static behaviors.
I checked `put` and `putAt` and I think there is consistency with `get` and
`getAt`. You can read and write via GString or String interchangeably. I
think this is the expectation of most users as described in 6668.
https://github.com/apache/groovy/pull/708
https://github.com/apache/groovy/pull/1766
https://issues.apache.org/jira/browse/GROOVY-6668
https://issues.apache.org/jira/browse/GROOVY-8212
> Static compiler doesn't coerce GString for getAt() call
> -------------------------------------------------------
>
> Key: GROOVY-6668
> URL: https://issues.apache.org/jira/browse/GROOVY-6668
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.3.0-beta-1, 2.4.0-rc-1
> Reporter: Luke Daley
> Assignee: Eric Milles
> Priority: Major
>
> This might not be a bug, but it's a behaviour change from 2.2.
> {code}
> @groovy.transform.CompileStatic
> class OtherThing {
> OtherThing() {
> Map<String, String> m = [:]
> def k = "foo"
> m["$k"].toUpperCase() // fails, no method toUpperCase() on object
> m[k].toUpperCase() // works
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)