Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler-v1] Omit warning for unused self parameter #14368

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

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) {
Tuple()
}
spec {
requires true;
}

} // end 0x42::m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module 0x42::m {

struct S has drop { x: u64 }

fun 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
5 changes: 5 additions & 0 deletions third_party/move/move-compiler/src/hlir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,11 @@ fn check_unused_locals(
DisplayVar::Tmp => panic!("ICE unused tmp"),
DisplayVar::Orig(vstr) => vstr,
};
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;
}
let loc = v.loc();
let msg = if signature.is_parameter(&v) {
format!(
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
@@ -0,0 +1,11 @@
module 0x42::m {

struct S has drop { x: u64 }

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

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