You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/08/19 19:03:46 UTC

[jira] [Commented] (GROOVY-7164) @CompileStatic transform gives unexpected result for default constructor

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

Shil Sinha commented on GROOVY-7164:
------------------------------------

In your case I think the behavior is expected since field assignment within the owning class isn't delegated to a setter. However, the exception you posted also occurs when invoking the constructor from an external class.

> @CompileStatic transform gives unexpected result for default constructor
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-7164
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7164
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.3.7, 2.4.0-rc-1
>            Reporter: Leonard Brünings
>            Assignee: Cédric Champeau
>
> The following snippet reproduces a type checking error
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Test {
>     private long timestamp
>     
>     Date getTimestamp() {
>         return timestamp ? new Date(timestamp) : null
>     }
>     
>     void setTimestamp (Date timestamp) {
>         this.timestamp = timestamp.time
>     }
>     
>     def main() {
>         new Test(timestamp: new Date())
>     }
> }
> {code}
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 16: [Static type checking] - Cannot assign value of type java.util.Date to variable of type long
>  @ line 16, column 27.
>            new Test(timestamp: new Date())
>                              ^
> 1 error
> {noformat}
> This is quite unexpected it should use the type of the getter and setter for the validation since they are used later on to assign the value and not the type of the underlying field.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)