groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-6629) static compilation fails with obscure message when only constructor is annotated
Date Thu, 01 Feb 2018 06:42:00 GMT

    [ 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:41 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}
We could certainly improve the error message and in fact even without fixing the underlying
issue, we could be a lot smarter. In my smaller example for instance, even though we have
a field, we don't have an initial value expression, so it would be safe to statically compile
this example.


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}
And a simpler example to trigger the error:
{code}
class TestBroken {
    private myField
    @groovy.transform.CompileStatic
    TestBroken() {}
}
{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)

Mime
View raw message