You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jochen Theodorou (JIRA)" <ji...@apache.org> on 2017/03/29 15:20:41 UTC

[jira] [Commented] (GROOVY-8137) Support type check for class fields

    [ https://issues.apache.org/jira/browse/GROOVY-8137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15947328#comment-15947328 ] 

Jochen Theodorou commented on GROOVY-8137:
------------------------------------------

I think the "type inference" is disabled for parameters. And while doing so nobody thought if it being valid for final variables at least

> 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)