diff --git a/parser/src/token.rs b/parser/src/token.rs index eae9ce842e..da5ceca4e8 100644 --- a/parser/src/token.rs +++ b/parser/src/token.rs @@ -426,7 +426,14 @@ impl<'input> Tokenizer<'input> { Some((_, '.')) => { self.bump(); // Skip '.' let (end, float) = self.take_while(start, is_digit); - (start, end, Token::FloatLiteral(float.parse().unwrap())) + match self.lookahead { + Some((_, ch)) if is_ident_start(ch) => { + return self.error(end, UnexpectedChar(ch)) + } + _ => { + (start, end, Token::FloatLiteral(float.parse().unwrap())) + } + } } Some((end, 'x')) => { self.bump(); // Skip 'x' @@ -926,6 +933,14 @@ mod test { ); } + #[test] + fn float_literals_unexpected_char() { + assert_eq!( + tokenizer(r#"12.3a"#).last(), + Some(error(loc(4), UnexpectedChar('a'))) + ); + } + #[test] fn line_comments() { test(