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

Generics and static type checking: "Cannot return value of type W on method returning type W"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.2
    • 2.3.3
    • Compiler
    • None
    • OS: Debian GNU/Linux 7 (32 bit)

    Description

      As discussed into the mailing list the following snippet makes the groovy compiler complain for

      [Static type checking] - Cannot return value of type W on method returning type W


      even if it is valid groovy code

      snippet.groovy
      import groovy.transform.TypeChecked
      
      class Wrapper {}
      
      @TypeChecked
      class Foo<W extends Wrapper> {
          W doIt (List<W> l) {
              l.iterator().next()//Static type check failure
          }
      }
      
      //new Foo().doIt([])//uncomment this line to run as a script on groovyConsole
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            davide.cavestro Davide Cavestro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: