Groovy
  1. Groovy
  2. GROOVY-6044

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

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.0-beta-1
    • Component/s: Static Type Checker
    • Labels:
      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.

        Activity

        OC created issue -
        Hide
        Cédric Champeau added a comment -

        The type checking extensions now support a new handler:

        incompatibleReturnType { returnStmt, inferredReturnType ->
            if (inferredReturnType==STRING_TYPE) {
                handled = true
            }
        }
        
        Show
        Cédric Champeau added a comment - The type checking extensions now support a new handler: incompatibleReturnType { returnStmt, inferredReturnType -> if (inferredReturnType==STRING_TYPE) { handled = true } }
        Cédric Champeau made changes -
        Field Original Value New Value
        Assignee Cedric Champeau [ melix ]
        Fix Version/s 2.2.0-beta-1 [ 19074 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12734957 ] Default workflow, editable Closed status [ 12746674 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12972442 ] Default workflow, editable Closed status [ 12980272 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        104d 17h 50m 1 Cédric Champeau 24/Jun/13 09:31
        Resolved Resolved Closed Closed
        15d 20h 10m 1 Paul King 10/Jul/13 05:42

          People

          • Assignee:
            Cédric Champeau
            Reporter:
            OC
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development