Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/syntax-bridge/src/lib.rs | 15 | ||||
| -rw-r--r-- | crates/syntax-bridge/src/tests.rs | 51 |
2 files changed, 64 insertions, 2 deletions
diff --git a/crates/syntax-bridge/src/lib.rs b/crates/syntax-bridge/src/lib.rs index 0dcf18a4ad..181f9a14e7 100644 --- a/crates/syntax-bridge/src/lib.rs +++ b/crates/syntax-bridge/src/lib.rs @@ -903,7 +903,20 @@ impl TtTreeSink<'_> { } self.text_pos += TextSize::of(text); } - None => unreachable!(), + None => { + self.error("illegal float literal".to_owned()); + self.inner.start_node(SyntaxKind::ERROR); + self.inner.token(SyntaxKind::FLOAT_NUMBER, text); + self.token_map.push(self.text_pos + TextSize::of(text), span); + self.inner.finish_node(); + self.inner.finish_node(); + + if !has_pseudo_dot { + self.inner.finish_node(); + } + + self.text_pos += TextSize::of(text); + } } self.cursor.bump(); } diff --git a/crates/syntax-bridge/src/tests.rs b/crates/syntax-bridge/src/tests.rs index 16f2498bf3..691084d8b0 100644 --- a/crates/syntax-bridge/src/tests.rs +++ b/crates/syntax-bridge/src/tests.rs @@ -1,3 +1,4 @@ +use expect_test::expect; use rustc_hash::FxHashMap; use span::Span; use syntax::{AstNode, ast}; @@ -7,7 +8,7 @@ use tt::{Leaf, Punct, Spacing, buffer::Cursor}; use crate::{ DocCommentDesugarMode, dummy_test_span_utils::{DUMMY, DummyTestSpanMap}, - syntax_node_to_token_tree, + parse_to_token_tree_static_span, syntax_node_to_token_tree, token_tree_to_syntax_node, }; fn check_punct_spacing(fixture: &str) { @@ -97,3 +98,51 @@ fn main() { "#, ); } + +#[test] +fn scientific_notation_field_access_recovers() { + let tt = parse_to_token_tree_static_span( + span::Edition::CURRENT, + DUMMY, + r#" +fn main() { + s.00E+10; +} +"#, + ) + .unwrap(); + + let (parse, _) = token_tree_to_syntax_node(&tt, parser::TopEntryPoint::SourceFile, &mut |_| { + span::Edition::CURRENT + }); + let parse = parse.cast::<ast::SourceFile>().unwrap(); + + expect![[r#" + [email protected] "fn" + [email protected] "main" + [email protected] "(" + [email protected] ")" + [email protected] "{" + [email protected] "s" + [email protected] "." + [email protected] "00E+10" + [email protected] ";" + [email protected] "}" + error 11..11: illegal float literal + "#]] + .assert_eq(&parse.debug_dump()); +} |