Factor out AST node for function return types. (#912)

This enables us to stop treating the return type as a Pattern (which is really isn't), treat return types more consistently with other static types in the typechecker, and drop ReturnTypeContext.

Additional changes:
- Merge TypeCheckFunDef with TypeOfFunDef.
- Handle implicit conversions in `return` statements.
- Require function type literals to have an explicit `->`.
- Move consistency check for omitted returns from TypeChecker to ResolveControlFlow.
This commit is contained in:
Geoff Romer
2021-11-12 11:30:31 -08:00
committed by GitHub
parent a4aff26821
commit d854fb93cb
11 changed files with 255 additions and 229 deletions
@@ -944,11 +944,11 @@ auto Interpreter::StepStmt() -> Transition {
} else {
// { {v :: return [] :: C, E, F} :: {C', E', F'} :: S, H}
// -> { {v :: C', E', F'} :: S, H}
// TODO(geoffromer): convert the result to the function's return type,
// once #880 gives us a way to find that type.
const FunctionDeclaration& function = cast<Return>(stmt).function();
return UnwindPast{.ast_node = *function.body(),
.result = act.results()[0]};
return UnwindPast{
.ast_node = *function.body(),
.result = Convert(act.results()[0],
&function.return_term().static_type())};
}
case Statement::Kind::Continuation: {
CHECK(act.pos() == 0);