You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/07/23 16:31:00 UTC
[jira] [Updated] (GROOVY-10628) Elvis assignment operator loses type information
[ https://issues.apache.org/jira/browse/GROOVY-10628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-10628:
---------------------------------
Fix Version/s: (was: 5.0.0-alpha-1)
> 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
> Fix For: 3.0.11, 4.0.3
>
>
> 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.10#820010)