Björn Kautler created GROOVY-12443:
--------------------------------------
Summary: STC: Bad error message when accessing dynamic property
Key: GROOVY-12443
URL: https://issues.apache.org/jira/browse/GROOVY-12443
Project: Groovy
Issue Type: Bug
Affects Versions: 5.1.2, 6.0.0-RC-1, 4.0.33, 5.0.3, 3.0.25, 2.5.23
Reporter: Björn Kautler
Given this snippet:
{code:groovy}
@groovy.transform.CompileStatic
def foo() {
def jvm = new Jvm()
for (i in 8..9) {
assert jvm."java$i"
}
}
foo()
@groovy.transform.CompileStatic
public class Jvm {
public boolean isJava8() {
return true
}
public boolean isJava9() {
return false
}
}
{code}
If you execute this in groovyconsole.dev, the error you get is
{code:java}
[Static type checking] - No such property: null for class: Jvm {code}
If you comment out the first line, it works as intended.
If you change the {{assert jvm."java$i"}} to {{assert jvm."isJava$i"()}} you get
{code:java}
[Static type checking] - Cannot resolve dynamic method name at compile
time{code}
When trying to access dynamic property under STC, you should get a similar
meaningful error message like
{code:java}
[Static type checking] - Cannot resolve dynamic property name at compile
time{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)