Skip to content

Commit

Permalink
Fix panic when lexing ".9" at the beginning of a file
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Mar 24, 2023
1 parent b8da155 commit 5d0fe58
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions solang-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,10 @@ impl<'input> Lexer<'input> {
self.chars.next();
}
let mut rational_end = end;
let mut end_before_rational = end;
let mut end_before_rational = end + 1;
let mut rational_start = end;
if is_rational {
end_before_rational = start - 1;
end_before_rational = start;
rational_start = start + 1;
}

Expand Down Expand Up @@ -666,7 +666,7 @@ impl<'input> Lexer<'input> {
}

if is_rational {
let integer = &self.input[start..=end_before_rational];
let integer = &self.input[start..end_before_rational];
let fraction = &self.input[rational_start..=rational_end];
let exp = &self.input[exp_start..=end];

Expand Down Expand Up @@ -1705,4 +1705,22 @@ fn lexertest() {
'g'
),)
);

let mut errors = Vec::new();
let tokens = Lexer::new(".9", 0, &mut comments, &mut errors)
.collect::<Vec<Result<(usize, Token, usize), LexicalError>>>();

assert_eq!(
tokens,
vec!(Ok((0, Token::RationalNumber("", "9", ""), 2)),)
);

let mut errors = Vec::new();
let tokens = Lexer::new(".9e10", 0, &mut comments, &mut errors)
.collect::<Vec<Result<(usize, Token, usize), LexicalError>>>();

assert_eq!(
tokens,
vec!(Ok((0, Token::RationalNumber("", "9", "10"), 5)),)
);
}

0 comments on commit 5d0fe58

Please sign in to comment.