[
https://issues.apache.org/jira/browse/GROOVY-12304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18138204#comment-18138204
]
ASF GitHub Bot commented on GROOVY-12304:
-----------------------------------------
paulk-asert commented on PR #3017:
URL: https://github.com/apache/groovy/pull/3017#issuecomment-6641008940
Thanks Daniel. On your points:
1. The new check is in recordMissingProperty, so it only runs once
existsProperty has failed and the type checking extensions have had their
chance. Everything it rejects was already a compile error, previously reported
as "No such property: null for class: …", the message Björn flagged on the
JIRA. So it can't reject anything that compiled before; it only explains the
error and points to subscript notation. A name without interpolation, such as
map."a", is a constant and never reaches the check.
2. FieldsAndPropertiesStaticCompileTest extends FieldsAndPropertiesSTCTest,
so these tests, including map[key] and date[key] via subscript, also run under
@CompileStatic.
3. Yes, that's intentional: the caret goes on the interpolated name, which
is what needs changing.
4. [a: 1]."a${''}" covers an interpolated name whose value is known at
compile time, and it's rejected like the others. As Jochen notes on the JIRA,
x."$name" follows a different path from x[name], so the checker leaves it alone
rather than guessing.
> 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
(v10.3.26#10030026)