Iurii created GROOVY-8137:
-----------------------------
Summary: Support type check for class fields
Key: GROOVY-8137
URL: https://issues.apache.org/jira/browse/GROOVY-8137
Project: Groovy
Issue Type: New Feature
Components: Static compilation
Affects Versions: 2.4.10
Environment: Windows 7, JDK 1.8.0_66
Reporter: Iurii
Compilation fails for the following code:
{code}
import groovy.transform.CompileStatic
@CompileStatic
class Test {
final KEY = 'key'
static void main(String[] args) {
new Test().foo()
}
def foo() {
def key = 'key'
key.contains('k')
KEY.contains('k')
}
}
{code}
Error:(14, 9) Groovyc: [Static type checking] - Cannot find matching method
java.lang.Object#contains(java.lang.String). Please check if the declared type
is right and if the method exists.
Expected behavior: compilation passes.
If Groovy can define local variable type from the assignment (key variable)
then it would be great if Groovy can do the same for class level field (KEY
variable).
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)