Skip to content

Commit

Permalink
solc does not warn or error for duplicate @param tags (#1320)
Browse files Browse the repository at this point in the history
Make it a warning and add note to previous doc tag, and fix the locations.

Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 22, 2023
1 parent 1a47714 commit a09b8b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/sema/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn resolve_tags(
for c in tags.iter().flat_map(DocComment::comments) {
let tag_loc = pt::Loc::File(file_no, c.tag_offset, c.tag_offset + c.tag.len() + 1);
let value_loc = pt::Loc::File(file_no, c.value_offset, c.value_offset + c.value.len());
let loc = pt::Loc::File(file_no, c.tag_offset, c.value_offset + c.value.len());
let loc = pt::Loc::File(file_no, c.tag_offset - 1, c.value_offset + c.value.len());

match c.tag.as_str() {
"notice" | "author" | "title" | "dev" => {
Expand Down Expand Up @@ -49,10 +49,13 @@ pub fn resolve_tags(
let value = v.get(1).unwrap_or(&"").to_string();

if let Some(no) = params.unwrap().iter().position(|p| p.name_as_str() == name) {
if res.iter().any(|e| e.tag == "param" && e.no == no) {
ns.diagnostics.push(Diagnostic::error(
tag_loc,
if let Some(other) = res.iter().find(|e| e.tag == "param" && e.no == no) {
// Note: solc does not detect this problem
ns.diagnostics.push(Diagnostic::warning_with_note(
loc,
format!("duplicate tag '@param' for '{name}'"),
other.loc,
format!("previous tag '@param' for '{name}'"),
));
} else {
res.push(Tag {
Expand Down
4 changes: 3 additions & 1 deletion tests/contract_testcases/substrate/tags/event_tag_02.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
uint32 f
);
// ---- Expect: diagnostics ----
// error: 3:14-20: duplicate tag '@param' for 'f'
// warning: 3:13-25: duplicate tag '@param' for 'f'
// note 2:13-27: previous tag '@param' for 'f'
// warning: 4:15-16: event 'x' has never been emitted
5 changes: 4 additions & 1 deletion tests/contract_testcases/substrate/tags/functions_02.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
function foo(int f) public {}
}
// ---- Expect: diagnostics ----
// error: 5:15-21: duplicate tag '@param' for 'f'
// warning: 5:14-27: duplicate tag '@param' for 'f'
// note 3:17-25: previous tag '@param' for 'f'
// warning: 7:13-39: function can be declared 'pure'
// warning: 7:30-31: function parameter 'f' has never been read
3 changes: 2 additions & 1 deletion tests/contract_testcases/substrate/tags/struct_tag_02.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
uint32 f;
}
// ---- Expect: diagnostics ----
// error: 3:14-20: duplicate tag '@param' for 'f'
// warning: 3:13-25: duplicate tag '@param' for 'f'
// note 2:13-27: previous tag '@param' for 'f'

0 comments on commit a09b8b9

Please sign in to comment.