Skip to content

Commit

Permalink
Fix lexing of multiline comments to include the trailing '/' (FuelLab…
Browse files Browse the repository at this point in the history
…s#2359)

* Fix lexing of multiline comments to include the trailing '/'

Previously, both the implementation and the test missed the trailing
slash during lexing. This fixes both, closes FuelLabs#2355 and unblocks FuelLabs#2311.

* Add missing slash to sway-fmt-v2 comment test
  • Loading branch information
mitchmindtree authored Jul 22, 2022
1 parent 6d3cbac commit 91a60a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sway-fmt-v2/src/utils/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod tests {
.unwrap();
assert_eq!(
found_comment.1.span.as_str(),
"/* multi-\n * line-\n * comment *"
"/* multi-\n * line-\n * comment */"
);
}
}
6 changes: 3 additions & 3 deletions sway-parse/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ pub fn lex_commented(
None => return Err(unclosed_multiline_comment(unclosed_indices)),
Some((_, '*')) => match char_indices.next() {
None => return Err(unclosed_multiline_comment(unclosed_indices)),
Some((end, '/')) => {
let _ = char_indices.next();
Some((slash_ix, '/')) => {
let start = unclosed_indices.pop().unwrap();
let end = slash_ix + '/'.len_utf8();
let span =
Span::new(src.clone(), start, end, path.clone()).unwrap();
let comment = Comment { span };
Expand Down Expand Up @@ -1135,7 +1135,7 @@ mod tests {
let mut tts = group.token_stream.token_trees().iter();
assert_eq!(
tts.next().unwrap().span().as_str(),
"/* multi-\n * line-\n * comment *",
"/* multi-\n * line-\n * comment */",
);
assert_eq!(tts.next().unwrap().span().as_str(), "bar");
assert_eq!(tts.next().unwrap().span().as_str(), ":");
Expand Down

0 comments on commit 91a60a6

Please sign in to comment.