You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/02/01 06:38:00 UTC

[jira] [Comment Edited] (GROOVY-6629) static compilation fails with obscure message when only constructor is annotated

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

Paul King edited comment on GROOVY-6629 at 2/1/18 6:37 AM:
-----------------------------------------------------------

Here is the comment about this message from {{StaticCompilationVisitor#checkForConstructorWithCSButClassWithout}}: 
{code}
    /**
     * If we are in a constructor, that is static compiled, but in a class, that
     * is not, it may happen that init code from object initializers, fields
     * or properties is added into the constructor code. The backend assumes
     * a purely static constructor, so it may fail if it encounters dynamic
     * code here. Thus we make this kind of code fail
     */
{code}
And a simpler example to trigger the error:
{code}
class TestBroken {
    private myField
    @groovy.transform.CompileStatic
    TestBroken() {}
}
{code}


was (Author: paulk):
Here is the comment about this message from {{StaticCompilationVisitor#checkForConstructorWithCSButClassWithout}}: 
{code}
    /**
     * If we are in a constructor, that is static compiled, but in a class, that
     * is not, it may happen that init code from object initializers, fields
     * or properties is added into the constructor code. The backend assumes
     * a purely static constructor, so it may fail if it encounters dynamic
     * code here. Thus we make this kind of code fail
     */
{code}

> static compilation fails with obscure message when only constructor is annotated
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-6629
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6629
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.2.2, 2.3.0, 2.4.0-rc-1
>            Reporter: Dimitar Dimitrov
>            Priority: Major
>
> {code}
> class TestBroken {
>     private final InetAddress bindTo
>     @groovy.transform.CompileStatic
>     TestBroken(InetAddress bindTo = null) {
>         this.bindTo = bindTo ?: InetAddress.getByName("localhost")
>     }
> }
> {code}
> Error:(12, 5) Groovyc: [Static type checking] - Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.
> {code}
> @groovy.transform.CompileStatic
> class TestWorking {
>     private final InetAddress bindTo
>     TestWorking(InetAddress bindTo = null) {
>         this.bindTo = bindTo ?: InetAddress.getByName("localhost")
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)