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:
Richard Smith
2022-10-04 15:39:04 -07:00
committed by GitHub
parent c703c89658
commit 8f0f69b65f
63 changed files with 254 additions and 264 deletions
+8 -8
View File
@@ -65,11 +65,11 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
&impl_witness->bindings());
}
} else {
return CompilationError(source_loc)
return ProgramError(source_loc)
<< "member " << f << " not in " << *witness;
}
} else {
return RuntimeError(source_loc)
return ProgramError(source_loc)
<< "member lookup for " << f << " in symbolic " << *witness;
}
}
@@ -78,7 +78,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
std::optional<Nonnull<const Value*>> field =
cast<StructValue>(*v).FindField(f);
if (field == std::nullopt) {
return RuntimeError(source_loc) << "member " << f << " not in " << *v;
return ProgramError(source_loc) << "member " << f << " not in " << *v;
}
return *field;
}
@@ -99,7 +99,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
std::optional<Nonnull<const FunctionValue*>> func =
class_type.FindFunction(f);
if (func == std::nullopt) {
return RuntimeError(source_loc) << "member " << f << " not in " << *v
return ProgramError(source_loc) << "member " << f << " not in " << *v
<< " or its " << class_type;
} else if ((*func)->declaration().is_method()) {
// Found a method. Turn it into a bound method.
@@ -116,7 +116,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
case Value::Kind::ChoiceType: {
const auto& choice = cast<ChoiceType>(*v);
if (!choice.FindAlternative(f)) {
return RuntimeError(source_loc)
return ProgramError(source_loc)
<< "alternative " << f << " not in " << *v;
}
return arena->New<AlternativeConstructorValue>(f, choice.name());
@@ -127,7 +127,7 @@ static auto GetMember(Nonnull<Arena*> arena, Nonnull<const Value*> v,
std::optional<Nonnull<const FunctionValue*>> fun =
class_type.FindFunction(f);
if (fun == std::nullopt) {
return RuntimeError(source_loc)
return ProgramError(source_loc)
<< "class function " << f << " not in " << *v;
}
return arena->New<FunctionValue>(&(*fun)->declaration(),
@@ -167,7 +167,7 @@ static auto SetFieldImpl(
return element.name == (*path_begin).name();
});
if (it == elements.end()) {
return RuntimeError(source_loc)
return ProgramError(source_loc)
<< "field " << (*path_begin).name() << " not in " << *value;
}
CARBON_ASSIGN_OR_RETURN(
@@ -188,7 +188,7 @@ static auto SetFieldImpl(
// TODO(geoffromer): update FieldPath to hold integers as well as strings.
int index = std::stoi(std::string((*path_begin).name()));
if (index < 0 || static_cast<size_t>(index) >= elements.size()) {
return RuntimeError(source_loc) << "index " << (*path_begin).name()
return ProgramError(source_loc) << "index " << (*path_begin).name()
<< " out of range in " << *value;
}
CARBON_ASSIGN_OR_RETURN(