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

Eric Milles commented on GROOVY-10628:
--------------------------------------

If you change "String to" to "public String to" or "void setTo(String to) { ... 
}" do you get the same thing?  There is some special property node handling and 
I'm trying to see if that is where the problem lies.

> Elvis assignment operator loses type information
> ------------------------------------------------
>
>                 Key: GROOVY-10628
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10628
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.2
>            Reporter: Christopher Smith
>            Priority: Major
>
> This class works as expected:
> {code}
> class RoutingInfo {
>   String to
>   void hello() { this.to ?= 'alice' }
> }
> {code}
> Trying to use Elvis assignment from a class _in another file_ (it must be 
> another file) causes the STC to lose track of the type of the RHS and 
> complain that it can't assign Object to String:
> {code}
> class Other {
>   void world() {
>     new RoutingInfo().to ?= 'bob'
>   }
> }
> {code}
> {code}
> Groovy:[Static type checking] - Cannot assign value of type java.lang.Object 
> to variable of type java.lang.String
> {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to