Skip to content

Commit

Permalink
Omit warning only for first parameter named self, to scope impact
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwg committed Aug 21, 2024
1 parent d464c05 commit b06e5e8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@

Diagnostics:
warning: Unused parameter `y`. Consider removing or prefixing with an underscore: `_y`
┌─ tests/checking/receiver/dont_warn_unused_self.move:5:27
5 │ fun receiver(self: S, y: u64) {
│ ^

// -- Model dump before bytecode pipeline
module 0x42::m {
struct S {
x: u64,
}
private fun receiver(self: m::S,_y: u64) {
private fun receiver(self: m::S,y: u64) {
Tuple()
}
spec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module 0x42::m {

struct S has drop { x: u64 }

fun receiver(self: S, _y: u64) {
fun receiver(self: S, y: u64) {
}

spec receiver(self: S, _y: u64) {
spec receiver(self: S, y: u64) {
requires true;
}
}
7 changes: 7 additions & 0 deletions third_party/move/move-compiler/src/hlir/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ impl FunctionSignature {
.iter()
.any(|(parameter_name, _)| parameter_name == v)
}

pub fn is_first_parameter(&self, v: &Var) -> bool {
self.parameters
.first()
.map(|(parameter_name, _)| parameter_name == v)
.unwrap_or(false)
}
}

impl Command_ {
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-compiler/src/hlir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ fn check_unused_locals(
DisplayVar::Tmp => panic!("ICE unused tmp"),
DisplayVar::Orig(vstr) => vstr,
};
if signature.is_parameter(&v) && vstr == "self" {
if signature.is_first_parameter(&v) && vstr == "self" {
// Special treatment for `self` Move 2 parameter: do not warn if unused
// for the case v1 compiles v2 code
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning[W09002]: unused variable
┌─ tests/move_check/locals/dont_warn_unused_self.move:5:27
5 │ fun receiver(self: S, y: u64) {
│ ^ Unused parameter 'y'. Consider removing or prefixing with an underscore: '_y'

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module 0x42::m {

struct S has drop { x: u64 }

fun receiver(self: S, _y: u64) {
fun receiver(self: S, y: u64) {
}

spec receiver(self: S, _y: u64) {
spec receiver(self: S, y: u64) {
requires true;
}
}

0 comments on commit b06e5e8

Please sign in to comment.