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

regression of return type from ternary operator

    Details

      Description

      In Groovy 2.4.5 the following code works, but in Groovy 2.4.6, it fails to compile:

      @groovy.transform.Field
      String x = "X"
      
      @groovy.transform.CompileStatic
      public List<String> getStrings() {
      	x ? [x] : Collections.emptyList()
      }
      
      getStrings()
      

      In Groovy 2.4.6 the compile error is:

      [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <? extends java.lang.Object> to: java.util.List <String>
       @ line 6, column 2.
          x ? [x] : Collections.emptyList()
          ^
      

      Workaround is to cast the result of emptyList to the erased type, (List) in this case.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                daniel_sun Daniel Sun
                Reporter:
                gillius Jason Winnebeck
              • Votes:
                2 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: