Skip to content

Commit

Permalink
fix: use self.span
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Dec 10, 2024
1 parent fd12acb commit 8728416
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
23 changes: 9 additions & 14 deletions crates/sema/src/ast_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,17 @@ impl<'ast> Visit<'ast> for AstValidator<'_, 'ast> {

if func.header.visibility.is_none() {
if let Some(contract) = self.contract {
if let Some(func_name) = func.header.name {
if func.kind.is_function() {
let suggested_visibility =
if contract.kind.is_interface() { "external" } else { "public" };
self.dcx()
.err("no visibility specified")
.span(func_name.span)
.help(format!("do you intend to add {suggested_visibility}?"))
.emit();
}
if let Some(suggested_visibility) = if func.kind.is_function() {
Some(if contract.kind.is_interface() { "external" } else { "public" })
} else if func.kind.is_fallback() || func.kind.is_receive() {
let function_name = func.kind.to_str().to_lowercase();
Some("external")
} else {
None
} {
self.dcx()
.err(format!("no visibility specified for {function_name}"))
.span(contract.name.span)
.help("do you intend to add external?")
.err("no visibility specified")
.span(self.span)
.help(format!("do you intend to add {suggested_visibility}?"))
.emit();
}
}
Expand Down
11 changes: 6 additions & 5 deletions tests/ui/resolve/func_visibility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ contract U1 {
function c() {} //~ERROR: no visibility specified

function d() public {}

function e() external {}
}

interface U2 {
function c() {} //~ERROR: no visibility specified
}

contract U3 { //~ERROR: no visibility specified for fallback
fallback() {}
contract U3 {
fallback() {} //~ERROR: no visibility specified
}

contract U4 {//~ERROR: no visibility specified for receive
receive() {}
contract U4 {
receive() {} //~ERROR: no visibility specified
}

contract U5 {
contract U5 {
fallback() external {}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/resolve/func_visibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ error: no visibility specified
--> ROOT/tests/ui/resolve/func_visibility.sol:LL:CC
|
LL | function c() {}
| ^
| ^^^^^^^^^^^^^^^
|
= help: do you intend to add public?

error: no visibility specified
--> ROOT/tests/ui/resolve/func_visibility.sol:LL:CC
|
LL | function c() {}
| ^
| ^^^^^^^^^^^^^^^
|
= help: do you intend to add external?

error: no visibility specified for fallback
error: no visibility specified
--> ROOT/tests/ui/resolve/func_visibility.sol:LL:CC
|
LL | contract U3 {
| ^^
LL | fallback() {}
| ^^^^^^^^^^^^^
|
= help: do you intend to add external?

error: no visibility specified for receive
error: no visibility specified
--> ROOT/tests/ui/resolve/func_visibility.sol:LL:CC
|
LL | contract U4 {
| ^^
LL | receive() {}
| ^^^^^^^^^^^^
|
= help: do you intend to add external?

Expand Down

0 comments on commit 8728416

Please sign in to comment.