[stanc3] Statement return types?

Hey @Matthijs,

Figured I’d post here instead of just emailing everyone - trying to get more of our new compiler talk out on the forums.

I was wondering what it means in the AST for a statement to have a return type?

Thanks,
Sean

They represent the type of any return statements that occur in them. This is for the purpose of type checking function bodies.

NoReturnType means that no branch of the statement contains a return.

Incomplete t means that some but not all branches of the statement contain a return where the value being returned was always of type t.

Complete t means that all branches of the statement contain a return where the value being returned was always of type t.

AnyReturnType means that all branches throw an exception (hence could be of any return type).

Ahh, makes sense. Thank you!

Was there any desire to have statements be used as expressions? I avoided it before because I thought it’d be potentially confusing.

In C++, the return type of a = b is the type of a, so that c = (a = b)sets both c and a equal to b.