mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +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:
@@ -45,6 +45,19 @@ void Declaration::Print(llvm::raw_ostream& out) const {
|
||||
}
|
||||
}
|
||||
|
||||
void ReturnTerm::Print(llvm::raw_ostream& out) const {
|
||||
switch (kind_) {
|
||||
case ReturnKind::Omitted:
|
||||
return;
|
||||
case ReturnKind::Auto:
|
||||
out << "-> auto";
|
||||
return;
|
||||
case ReturnKind::Expression:
|
||||
out << "-> " << **type_expression_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionDeclaration::PrintDepth(int depth, llvm::raw_ostream& out) const {
|
||||
out << "fn " << name_ << " ";
|
||||
if (!deduced_parameters_.empty()) {
|
||||
@@ -60,10 +73,7 @@ void FunctionDeclaration::PrintDepth(int depth, llvm::raw_ostream& out) const {
|
||||
}
|
||||
out << "]";
|
||||
}
|
||||
out << *param_pattern_;
|
||||
if (!is_omitted_return_type_) {
|
||||
out << " -> " << *return_type_;
|
||||
}
|
||||
out << *param_pattern_ << return_term_;
|
||||
if (body_) {
|
||||
out << " {\n";
|
||||
(*body_)->PrintDepth(depth, out);
|
||||
|
||||
Reference in New Issue
Block a user