Skip to content

Commit

Permalink
Fix line comments that end in non-ascii character
Browse files Browse the repository at this point in the history
The lexer assumed the last character was 1 byte.

Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Feb 10, 2022
1 parent f850719 commit b286b63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions solang-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,10 @@ impl<'input> Lexer<'input> {

if !newline {
for (i, ch) in &mut self.chars {
last = i;
if ch == '\n' || ch == '\r' {
break;
}
last = i;
}
}

Expand All @@ -916,15 +916,15 @@ impl<'input> Lexer<'input> {
start + 3,
Token::DocComment(
CommentType::Line,
&self.input[doc_start..=last],
&self.input[doc_start..last],
),
last + 1,
last,
)));
}
} else {
self.comments.push(Comment::Line(
Loc(self.file_no, start, last + 1),
self.input[start..=last].to_owned(),
Loc(self.file_no, start, last),
self.input[start..last].to_owned(),
));
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/contract_testcases/solana/comment.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
strict digraph "tests/contract_testcases/solana/comment.sol" {
contract [label="contract Hello\ntests/contract_testcases/solana/comment.sol:1:24-2:16"]
diagnostic [label="pragma ‘solidity’ is ignored\nlevel Debug\ntests/contract_testcases/solana/comment.sol:1:8-23"]
diagnostic_6 [label="found contract ‘Hello’\nlevel Debug\ntests/contract_testcases/solana/comment.sol:1:24-2:16"]
contracts -> contract
diagnostics -> diagnostic [label="Debug"]
diagnostics -> diagnostic_6 [label="Debug"]
}
5 changes: 5 additions & 0 deletions tests/contract_testcases/solana/comment.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity ^0.8.0;
contract Hello {
// xxx 。
}

0 comments on commit b286b63

Please sign in to comment.