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> {
|
pub const fn ln_begin(&self) -> Option<usize> {
|
||||||
match self {
|
match self {
|
||||||
Self::Range { ln_begin, .. } | Self::LineRange(ln_begin, _) | Self::Line(ln_begin) => {
|
Self::Range { ln_begin, .. } | Self::LineRange(ln_begin, _) | Self::Line(ln_begin) => {
|
||||||
|
@ -477,7 +489,7 @@ impl SubMessage {
|
||||||
mark: char,
|
mark: char,
|
||||||
chars: &Characters,
|
chars: &Characters,
|
||||||
) -> String {
|
) -> String {
|
||||||
match self.loc {
|
match self.loc.unknown_or(e.core().loc) {
|
||||||
Location::Range {
|
Location::Range {
|
||||||
ln_begin,
|
ln_begin,
|
||||||
col_begin,
|
col_begin,
|
||||||
|
@ -752,6 +764,8 @@ pub trait ErrorDisplay {
|
||||||
for sub_msg in &core.sub_messages {
|
for sub_msg in &core.sub_messages {
|
||||||
msg += &sub_msg.format_code_and_pointer(self, color, gutter_color, mark, chars);
|
msg += &sub_msg.format_code_and_pointer(self, color, gutter_color, mark, chars);
|
||||||
}
|
}
|
||||||
|
msg += &core.kind.to_string();
|
||||||
|
msg += ": ";
|
||||||
msg += &core.main_message;
|
msg += &core.main_message;
|
||||||
msg += "\n\n";
|
msg += "\n\n";
|
||||||
msg
|
msg
|
||||||
|
|
|
@ -262,7 +262,9 @@ impl Context {
|
||||||
match subr {
|
match subr {
|
||||||
ConstSubr::User(_user) => todo!(),
|
ConstSubr::User(_user) => todo!(),
|
||||||
ConstSubr::Builtin(builtin) => builtin.call(args, self).map_err(|mut e| {
|
ConstSubr::Builtin(builtin) => builtin.call(args, self).map_err(|mut e| {
|
||||||
|
if e.0.loc.is_unknown() {
|
||||||
e.0.loc = loc;
|
e.0.loc = loc;
|
||||||
|
}
|
||||||
EvalErrors::from(EvalError::new(
|
EvalErrors::from(EvalError::new(
|
||||||
*e.0,
|
*e.0,
|
||||||
self.cfg.input.clone(),
|
self.cfg.input.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue