Add handling for return types. (#2596)

This starts handling return types on functions, and comparing types with `return` statements.

Note, errors remain poor because the type literal is currently associated with a builtin, losing the parse_node that specified it. This means we don't have the original source location to associate with, even though it may be helpful to point at the type in source. We could point at the signature overall, but my leaning is that we wouldn't want that long-term, so TODOs for now and may want to change a little about how the parse node is tracked once things are a little further along.
This commit is contained in:
Jon Ross-Perkins
2023-02-22 11:55:32 -08:00
committed by GitHub
parent 5d88871682
commit 2adaeee2ba
13 changed files with 259 additions and 26 deletions
@@ -168,9 +168,16 @@ class SemanticsParseTreeHandler {
// node in blocks here.
SemanticsNodeBlockStack params_or_args_stack_;
// Completed parameters that are held temporarily on a side-channel for a
// function. This can't use node_stack_ because it has space for only one
// value, whereas parameters return two values.
llvm::SmallVector<std::pair<SemanticsNodeBlockId, SemanticsNodeBlockId>>
finished_params_stack_;
// A stack of return scopes; i.e., targets for `return`. Inside a function,
// this will be a FunctionDeclaration.
llvm::SmallVector<SemanticsNodeId> return_scope_stack_;
// A stack for scope context.
llvm::SmallVector<ScopeStackEntry> scope_stack_;