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

strange behavior with lists involving generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.1
    • Static Type Checker
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: