Feature destructor (#2116)

This commit is contained in:
pmqtt
2022-09-26 10:11:05 -07:00
committed by GitHub
parent c63ae9b05d
commit cfa295c0af
29 changed files with 827 additions and 82 deletions
@@ -18,7 +18,7 @@ namespace Carbon {
// Aggregate information about a function being analyzed.
struct FunctionData {
// The function declaration.
Nonnull<FunctionDeclaration*> declaration;
Nonnull<CallableDeclaration*> declaration;
// True if the function has a deduced return type, and we've already seen
// a `return` statement in its body.
@@ -72,6 +72,7 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
"signature.";
}
}
return Success();
}
case StatementKind::Break:
@@ -138,12 +139,13 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
auto ResolveControlFlow(Nonnull<Declaration*> declaration) -> ErrorOr<Success> {
switch (declaration->kind()) {
case DeclarationKind::DestructorDeclaration:
case DeclarationKind::FunctionDeclaration: {
auto& function = cast<FunctionDeclaration>(*declaration);
if (function.body().has_value()) {
FunctionData data = {.declaration = &function};
auto& callable = cast<CallableDeclaration>(*declaration);
if (callable.body().has_value()) {
FunctionData data = {.declaration = &callable};
CARBON_RETURN_IF_ERROR(
ResolveControlFlow(*function.body(), std::nullopt, &data));
ResolveControlFlow(*callable.body(), std::nullopt, &data));
}
break;
}