groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shil Sinha <>
Subject Re: infer return type of script
Date Mon, 21 Sep 2015 21:30:19 GMT
You could call 'getInferredReturnType' on the 'run' method node of your
script class, but inferred return types only appear to be stored for
closures and certain binary expressions (based on the usages of the
INFERRED_RETURN_TYPE marker and the storeInferredReturnType method).

You could also add all implicit return statements to the 'run' method via
ReturnAdder, and then infer a return type by visiting all of the return
statements, but I'm not sure if that kind of AST modification in a type
checking extension is safe.


On Mon, Sep 21, 2015 at 4:34 PM, Jamie Echlin <>

> Hi...
> Is it possible to infer the return type, or types of a script during
> static compilation? Presumably there is always a finite list of branches
> where the script could end.
> I'm looking
> at,
> but I'm not really sure how to call it from a type checking script, nor
> what adds the inferred return type to the metadata which is used in that
> method.
> cheers, jamie

View raw message