mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Switch from llvm::errs()+exit() to FATAL_USER_ERROR() stream-based handling. (#670)
This is intended to: - Standardize use of line_num (and highlight where no line_num is available). - Standardize indications of runtime/compilation errors. - Make it incrementally easier to write new errors. Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Chandler Carruth
parent
dcc694c2e0
commit
f0af3cb795
@@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/check.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
|
||||
namespace Carbon {
|
||||
@@ -264,24 +265,21 @@ auto GetMember(const Value* v, const std::string& f, int line_num)
|
||||
const Value* field =
|
||||
v->GetStructValue().inits->GetTupleValue().FindField(f);
|
||||
if (field == nullptr) {
|
||||
llvm::errs() << "runtime error, member " << f << " not in " << *v
|
||||
<< "\n";
|
||||
exit(-1);
|
||||
FATAL_RUNTIME_ERROR(line_num) << "member " << f << " not in " << *v;
|
||||
}
|
||||
return field;
|
||||
}
|
||||
case ValKind::TupleValue: {
|
||||
const Value* field = v->GetTupleValue().FindField(f);
|
||||
if (field == nullptr) {
|
||||
llvm::errs() << "field " << f << " not in " << *v << "\n";
|
||||
exit(-1);
|
||||
FATAL_RUNTIME_ERROR(line_num) << "field " << f << " not in " << *v;
|
||||
}
|
||||
return field;
|
||||
}
|
||||
case ValKind::ChoiceType: {
|
||||
if (FindInVarValues(f, v->GetChoiceType().alternatives) == nullptr) {
|
||||
llvm::errs() << "alternative " << f << " not in " << *v << "\n";
|
||||
exit(-1);
|
||||
FATAL_RUNTIME_ERROR(line_num)
|
||||
<< "alternative " << f << " not in " << *v;
|
||||
}
|
||||
return Value::MakeAlternativeConstructorValue(f, v->GetChoiceType().name);
|
||||
}
|
||||
@@ -323,8 +321,8 @@ auto SetFieldImpl(const Value* value,
|
||||
return element.name == *path_begin;
|
||||
});
|
||||
if (it == elements.end()) {
|
||||
llvm::errs() << "field " << *path_begin << " not in " << *value << "\n";
|
||||
exit(-1);
|
||||
FATAL_RUNTIME_ERROR(line_num)
|
||||
<< "field " << *path_begin << " not in " << *value;
|
||||
}
|
||||
it->value = SetFieldImpl(it->value, path_begin + 1, path_end, field_value,
|
||||
line_num);
|
||||
|
||||
Reference in New Issue
Block a user