From c27f9d4b600b2c26a45f1fae86b438d31a281f83 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Fri, 22 Jul 2022 10:52:22 +1000 Subject: [PATCH 1/2] 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 #2355 and unblocks #2311. --- sway-parse/src/token.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway-parse/src/token.rs b/sway-parse/src/token.rs index 9bedd29e088..d6ab9664846 100644 --- a/sway-parse/src/token.rs +++ b/sway-parse/src/token.rs @@ -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 }; @@ -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(), ":"); From 35da25ec0e1f1a5185de66500a0c509b4f4509d9 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Fri, 22 Jul 2022 11:18:54 +1000 Subject: [PATCH 2/2] Add missing slash to sway-fmt-v2 comment test --- sway-fmt-v2/src/utils/comments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway-fmt-v2/src/utils/comments.rs b/sway-fmt-v2/src/utils/comments.rs index b412f4bfaab..b867a787328 100644 --- a/sway-fmt-v2/src/utils/comments.rs +++ b/sway-fmt-v2/src/utils/comments.rs @@ -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 */" ); } }