mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 11:31:05 +01:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user