Christopher Smith created GROOVY-10628:
------------------------------------------

             Summary: 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


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