mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
fix: panic when split float numbers in scientific notation
This commit is contained in:
parent
52d8ae791d
commit
03420c330e
1 changed files with 20 additions and 2 deletions
|
@ -190,7 +190,7 @@ impl Builder<'_, '_> {
|
||||||
|
|
||||||
fn do_float_split(&mut self, has_pseudo_dot: bool) {
|
fn do_float_split(&mut self, has_pseudo_dot: bool) {
|
||||||
let text = &self.lexed.range_text(self.pos..self.pos + 1);
|
let text = &self.lexed.range_text(self.pos..self.pos + 1);
|
||||||
self.pos += 1;
|
|
||||||
match text.split_once('.') {
|
match text.split_once('.') {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
assert!(!left.is_empty());
|
assert!(!left.is_empty());
|
||||||
|
@ -216,9 +216,27 @@ impl Builder<'_, '_> {
|
||||||
self.state = State::PendingExit;
|
self.state = State::PendingExit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => unreachable!(),
|
None => {
|
||||||
|
// illegal float literal which doesn't have dot in form (like 1e0)
|
||||||
|
// we should emit an error node here
|
||||||
|
(self.sink)(StrStep::Error { msg: "illegal float literal", pos: self.pos });
|
||||||
|
(self.sink)(StrStep::Enter { kind: SyntaxKind::ERROR });
|
||||||
|
(self.sink)(StrStep::Token { kind: SyntaxKind::FLOAT_NUMBER, text: text });
|
||||||
|
(self.sink)(StrStep::Exit);
|
||||||
|
|
||||||
|
// move up
|
||||||
|
(self.sink)(StrStep::Exit);
|
||||||
|
|
||||||
|
self.state = if has_pseudo_dot {
|
||||||
|
State::Normal
|
||||||
|
} else {
|
||||||
|
State::PendingExit
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.pos += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n_attached_trivias<'a>(
|
fn n_attached_trivias<'a>(
|
||||||
|
|
Loading…
Reference in a new issue