mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 12:51:10 +00:00
Add Location::unknown_or
This commit is contained in:
parent
de39186103
commit
c8b161842a
2 changed files with 18 additions and 2 deletions
|
@ -279,6 +279,18 @@ impl Location {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn is_unknown(&self) -> bool {
|
||||
matches!(self, Self::Unknown)
|
||||
}
|
||||
|
||||
pub const fn unknown_or(&self, other: Self) -> Self {
|
||||
if self.is_unknown() {
|
||||
other
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn ln_begin(&self) -> Option<usize> {
|
||||
match self {
|
||||
Self::Range { ln_begin, .. } | Self::LineRange(ln_begin, _) | Self::Line(ln_begin) => {
|
||||
|
@ -477,7 +489,7 @@ impl SubMessage {
|
|||
mark: char,
|
||||
chars: &Characters,
|
||||
) -> String {
|
||||
match self.loc {
|
||||
match self.loc.unknown_or(e.core().loc) {
|
||||
Location::Range {
|
||||
ln_begin,
|
||||
col_begin,
|
||||
|
@ -752,6 +764,8 @@ pub trait ErrorDisplay {
|
|||
for sub_msg in &core.sub_messages {
|
||||
msg += &sub_msg.format_code_and_pointer(self, color, gutter_color, mark, chars);
|
||||
}
|
||||
msg += &core.kind.to_string();
|
||||
msg += ": ";
|
||||
msg += &core.main_message;
|
||||
msg += "\n\n";
|
||||
msg
|
||||
|
|
|
@ -262,7 +262,9 @@ impl Context {
|
|||
match subr {
|
||||
ConstSubr::User(_user) => todo!(),
|
||||
ConstSubr::Builtin(builtin) => builtin.call(args, self).map_err(|mut e| {
|
||||
if e.0.loc.is_unknown() {
|
||||
e.0.loc = loc;
|
||||
}
|
||||
EvalErrors::from(EvalError::new(
|
||||
*e.0,
|
||||
self.cfg.input.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue