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

Add handler for "Cannot return value of type Foo on method returning type Bar" error

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.2.0-beta-1
    • Static Type Checker
    • None

    Description

      The "Cannot return value of type Foo on method returning type Bar" at the moment cannot be handled by typechecking extensions scripts.

      It, alas, does happen with otherwise perfectly valid code like e.g.,

      def valueForKey(key) { // can return effectively anything
        myLocalStorageMap[key]
      }
      Map foo() { // here we happen to know a Map always comes out
        valueForKey('thisKeyDoesAlwaysRepresentAMap')
      }
      

      Of course, adding an explicit typecast into the source helps. But I've thought it's the typechecking extension very raison d'être to allow such things to go trough the typechecker without having to typecast explicitly in the code – the extension would say to the typechecker essentially "Yup, I know, it's all right here, let it pass".

      The priority is minor since there are other possible work-arounds (namely, pusing the error collector and filtering these errors out later). Nevertheless direct support by a specific handler would be much better, for there would be more contextual information at the moment.

      Attachments

        Activity

          People

            melix Cédric Champeau
            oc OC
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: