-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harden peek()
/ peek_data()
call pairs in the parser
#830
Labels
Comments
peek_token()
calls in the parserpeek()
/ peek_data()
call pairs in the parser
surajk-m
added a commit
to surajk-m/apollo-rs
that referenced
this issue
Aug 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have a few places where we call
peek()
to check an upcoming token's kind, and thenpeek_data().unwrap()
to check its value. For example, to identify what type of definition is coming up:type
,union
, or something else. This is an actual self-contained snippet showing what I mean:apollo-rs/crates/apollo-parser/src/parser/grammar/object.rs
Lines 27 to 33 in 6c9adc4
The
unwrap()
call is valid in those cases, but a bit icky. For it to be valid, the current token must not change between those calls, and this is not statically verifiable. A mistake in a refactor could disconnect thepeek()
andpeek_data()
calls and then the unwrap could panic.I'd like to see these refactored to use
let Some(token) = peek_token()
where possible, and then usetoken.kind
/token.data
directly, so there is no way that it could ever panic.The text was updated successfully, but these errors were encountered: