[
https://issues.apache.org/jira/browse/GROOVY-12304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18108516#comment-18108516
]
Jochen Theodorou edited comment on GROOVY-12304 at 8/26/26 8:11 PM:
--------------------------------------------------------------------
foo[x] is foo.getAt( x). You do not need to know x to resolve this, if you know
it is a kind of String. foo."${x}" is a very different code path. It can maybe
be done, but it will result in a potential dynamic lookup resulting in
foo."${x}" being potentially different from foo.bar, even if x="bar".
was (Author: blackdrag):
foo[x] is foo.getAt(x). You do not need to know x to resolve this, if you know
it is a kind of String. foo."${x}" is a very different code path. It can maybe
be done, but it will result in a potential dynamic lookup resulting in
foo."${x}" being potentially different from foo.bar, even if x="bar".
> STC: Map access with dynamic key in dot-syntax does not compile
> ---------------------------------------------------------------
>
> Key: GROOVY-12304
> URL: https://issues.apache.org/jira/browse/GROOVY-12304
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0-alpha-1, 5.0.3, 4.0.31
> Reporter: Björn Kautler
> Priority: Major
>
> This does not compile:
> {code:java}
> @groovy.transform.CompileStatic
> class Foo {
> def foo(bar) {
> println([a: 1]."a${''}")
> }
> }
> new Foo().foo("foo") {code}
> with square brackets syntax it compiles and works from Groovy 5 on.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)