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 authored and GitHub committed 2021-11-12 11:30:31 -08:00
1 parent a4aff26821
commit d854fb93cb
11 files changed
+255 -229

No files matched your search

@@ -32,8 +32,7 @@ static void AddIntrinsics(Nonnull<Arena*> arena,
auto print = arena->New<FunctionDeclaration>(
source_loc, "Print", std::vector<Nonnull<GenericBinding*>>(),
arena->New<TuplePattern>(source_loc, print_params),
arena->New<ExpressionPattern>(arena->New<TupleLiteral>(source_loc)),
/*is_omitted_return_type=*/false, print_return);
ReturnTerm::Explicit(arena->New<TupleLiteral>(source_loc)), print_return);
declarations->insert(declarations->begin(), print);
}