mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Remove RuntimeError / CompilationError. (#2258)
Instead, work out the prefix for an error based on whether it was produced during parsing, semantic analysis, or when running the program.
This commit is contained in:
@@ -40,14 +40,14 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
case StatementKind::ReturnVar:
|
||||
case StatementKind::ReturnExpression: {
|
||||
if (!function.has_value()) {
|
||||
return CompilationError(statement->source_loc())
|
||||
return ProgramError(statement->source_loc())
|
||||
<< "return is not within a function body";
|
||||
}
|
||||
const ReturnTerm& function_return =
|
||||
(*function)->declaration->return_term();
|
||||
if (function_return.is_auto()) {
|
||||
if ((*function)->saw_return_in_auto) {
|
||||
return CompilationError(statement->source_loc())
|
||||
return ProgramError(statement->source_loc())
|
||||
<< "Only one return is allowed in a function with an `auto` "
|
||||
"return type.";
|
||||
}
|
||||
@@ -57,7 +57,7 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
ret.set_function((*function)->declaration);
|
||||
if (statement->kind() == StatementKind::ReturnVar &&
|
||||
function_return.is_omitted()) {
|
||||
return CompilationError(statement->source_loc())
|
||||
return ProgramError(statement->source_loc())
|
||||
<< *statement
|
||||
<< " should not provide a return value, to match the function's "
|
||||
"signature.";
|
||||
@@ -65,7 +65,7 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
if (statement->kind() == StatementKind::ReturnExpression) {
|
||||
auto& ret_exp = cast<ReturnExpression>(*statement);
|
||||
if (ret_exp.is_omitted_expression() != function_return.is_omitted()) {
|
||||
return CompilationError(ret_exp.source_loc())
|
||||
return ProgramError(ret_exp.source_loc())
|
||||
<< ret_exp << " should"
|
||||
<< (function_return.is_omitted() ? " not" : "")
|
||||
<< " provide a return value, to match the function's "
|
||||
@@ -77,14 +77,14 @@ static auto ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
}
|
||||
case StatementKind::Break:
|
||||
if (!loop.has_value()) {
|
||||
return CompilationError(statement->source_loc())
|
||||
return ProgramError(statement->source_loc())
|
||||
<< "break is not within a loop body";
|
||||
}
|
||||
cast<Break>(*statement).set_loop(*loop);
|
||||
return Success();
|
||||
case StatementKind::Continue:
|
||||
if (!loop.has_value()) {
|
||||
return CompilationError(statement->source_loc())
|
||||
return ProgramError(statement->source_loc())
|
||||
<< "continue is not within a loop body";
|
||||
}
|
||||
cast<Continue>(*statement).set_loop(*loop);
|
||||
|
||||
Reference in New Issue
Block a user