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
+2 -8
View File
@@ -352,12 +352,10 @@ class FunctionTypeLiteral : public Expression {
public:
explicit FunctionTypeLiteral(SourceLocation source_loc,
Nonnull<Expression*> parameter,
Nonnull<Expression*> return_type,
bool is_omitted_return_type)
Nonnull<Expression*> return_type)
: Expression(Kind::FunctionTypeLiteral, source_loc),
parameter_(parameter),
return_type_(return_type),
is_omitted_return_type_(is_omitted_return_type) {}
return_type_(return_type) {}
static auto classof(const Expression* exp) -> bool {
return exp->kind() == Kind::FunctionTypeLiteral;
@@ -367,14 +365,10 @@ class FunctionTypeLiteral : public Expression {
auto parameter() -> Expression& { return *parameter_; }
auto return_type() const -> const Expression& { return *return_type_; }
auto return_type() -> Expression& { return *return_type_; }
auto is_omitted_return_type() const -> bool {
return is_omitted_return_type_;
}
private:
Nonnull<Expression*> parameter_;
Nonnull<Expression*> return_type_;
bool is_omitted_return_type_;
};
class BoolTypeLiteral : public Expression {