Function return type from ReturnStmt


I’m trying to get the return type for the function associated with a ReturnStmt AST node.

The type of the return expression is easy as that’s available via getRetValue(), but I can’t see an obvious way to get the return type of the function (so I can check the two match).

Any pointers would be greatly appreciated !


Until somebody who definitely knows this answers, how about

Thanks, but that gives the type of the return expression. I’m after the function prototype (if there is one) so I can do some checking between the expected and actual types.


The expression in the ReturnStmt will have been implicitly converted to the return type, so unless you’re writing an AST verifier, there is nothing to do here.

You probably want to look past any implicit conversions and see what expression was actually written.


Of course, that makes sense. The top-most type will always be the same as the return type. (Bangs head on desk !).

Looking through the implicit cast does then allow me to check for ‘undesirable’ type conversions.

Thanks, I knew it would be easy :wink: