[
https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17539750#comment-17539750
]
Eric Milles edited comment on GROOVY-10628 at 5/19/22 7:09 PM:
---------------------------------------------------------------
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.
Update: field works fine. Must have something to do with property.
was (Author: emilles):
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
> Assignee: Eric Milles
> 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)