Skip to content

Commit

Permalink
fix: location calculation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Aug 11, 2024
1 parent 1523515 commit 0f6546d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/erg_common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl fmt::Display for Location {
col_end,
} => write!(f, "{ln_begin}:{col_begin}-{ln_end}:{col_end}"),
Self::LineRange(ln_begin, ln_end) => write!(f, "{ln_begin}:?-{ln_end}:?"),
Self::Line(ln) => write!(f, "{ln}:?-{ln}:?"),
Self::Line(ln) => write!(f, "{ln}:??-{ln}:??"),
Self::Unknown => write!(f, "?"),
}
}
Expand Down Expand Up @@ -427,11 +427,11 @@ impl Location {
pub fn stream<L: Locational>(ls: &[L]) -> Self {
if ls.is_empty() {
return Self::Unknown;
};
}
let Some(first_known) = ls.iter().find(|l| !l.loc().is_unknown()) else {
return Self::Unknown;
};
let Some(last_known) = ls.iter().rev().find(|l| !l.loc().is_unknown()) else {
let Some(last_known) = ls.iter().rfind(|l| !l.loc().is_unknown()) else {
return Self::Unknown;
};
Self::concat(first_known, last_known)
Expand Down Expand Up @@ -481,7 +481,7 @@ impl Location {

pub const fn ln_end(&self) -> Option<u32> {
match self {
Self::Range { ln_end, .. } | Self::LineRange(ln_end, _) | Self::Line(ln_end) => {
Self::Range { ln_end, .. } | Self::LineRange(_, ln_end) | Self::Line(ln_end) => {
Some(*ln_end)
}
Self::Unknown => None,
Expand Down
8 changes: 2 additions & 6 deletions crates/erg_parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,11 +1212,7 @@ impl NestedDisplay for ClassAttrs {

impl Locational for ClassAttrs {
fn loc(&self) -> Location {
if self.is_empty() {
Location::Unknown
} else {
Location::concat(self.0.first().unwrap(), self.0.last().unwrap())
}
Location::stream(&self.0)
}
}

Expand Down Expand Up @@ -5778,7 +5774,7 @@ impl NestedDisplay for Methods {
}

impl_display_from_nested!(Methods);
impl_locational!(Methods, class, attrs);
impl_locational!(Methods, lossy class, attrs);

impl Methods {
pub fn new(
Expand Down

0 comments on commit 0f6546d

Please sign in to comment.