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

strange behavior with lists involving generics

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.1
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      this works fine:

      @groovy.transform.TypeChecked
      def test() {
          List<GString> dates = ["${new Date()-1}", "${new Date()}", "${new Date()+1}"]
          List<String> upper = dates*.toUpperCase()
      }
      test()
      

      but this fails:

      @groovy.transform.TypeChecked
      def test() {
          List<GString> dates = ["${new Date()-1}", "${new Date()}", "${new Date()+1}"]
          List<GString> copied = []
          copied.addAll(dates)
          List<String> upper = copied*.toUpperCase()
      }
      test()
      

      with this error message:

      2 compilation errors:
      
      [Static type checking] - Cannot find matching method groovy.lang.GString#toUpperCase(). Please check if the declared type is right and if the method exists.
       at line: 6, column: 26
      
      [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <java.lang.Object> to: java.util.List <String>
       at line: 6, column: 5
      

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              paulk Paul King
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: