mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +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:
@@ -198,9 +198,10 @@ class Return : public Statement {
|
||||
// structure of the AST: the return value is not a child of this node,
|
||||
// but an ancestor.
|
||||
auto function() const -> const FunctionDeclaration& { return **function_; }
|
||||
auto function() -> FunctionDeclaration& { return **function_; }
|
||||
|
||||
// Can only be called once, by ResolveControlFlow.
|
||||
void set_function(Nonnull<const FunctionDeclaration*> function) {
|
||||
void set_function(Nonnull<FunctionDeclaration*> function) {
|
||||
CHECK(!function_.has_value());
|
||||
function_ = function;
|
||||
}
|
||||
@@ -208,7 +209,7 @@ class Return : public Statement {
|
||||
private:
|
||||
Nonnull<Expression*> expression_;
|
||||
bool is_omitted_expression_;
|
||||
std::optional<Nonnull<const FunctionDeclaration*>> function_;
|
||||
std::optional<Nonnull<FunctionDeclaration*>> function_;
|
||||
};
|
||||
|
||||
class While : public Statement {
|
||||
|
||||
Reference in New Issue
Block a user