Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10628

Elvis assignment operator loses type information

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.2
    • 3.0.11, 4.0.3
    • Static Type Checker
    • None

    Description

      This class works as expected:

      class RoutingInfo {
        String to
      
        void hello() { this.to ?= 'alice' }
      }
      

      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:

      class Other {
        void world() {
          new RoutingInfo().to ?= 'bob'
        }
      }
      
      Groovy:[Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.String
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: