Skip to content

Commit be7d783

Browse files
committed
Reject duplicate call arguments
1 parent 896baa7 commit be7d783

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/checks/calls.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,27 @@ fn check_call_args(
120120
.map(|param| param.name.clone())
121121
.collect();
122122

123+
let mut seen_names = HashSet::new();
123124
for arg in args {
124125
let Some(name) = &arg.name else {
125126
continue;
126127
};
128+
if !seen_names.insert(name.as_str()) {
129+
analyzer.diagnostics.push(
130+
Diagnostic::error(
131+
code::DUPLICATE_ARGUMENT,
132+
format!("call to `{call_name}` repeats argument `{name}`."),
133+
arg.span.clone(),
134+
"duplicate argument",
135+
)
136+
.with_cause("Each named parameter can be provided at most once.")
137+
.with_fix(
138+
"remove_duplicate_argument",
139+
format!("Remove the extra `{name}: ...` argument."),
140+
"manual",
141+
),
142+
);
143+
}
127144
if !param_names.contains(name) {
128145
analyzer.diagnostics.push(
129146
Diagnostic::error(

src/diagnostic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod code {
1010
pub const MISSING_DATA_EFFECT: &str = "RS0202";
1111
pub const UNKNOWN_ARGUMENT: &str = "RS0203";
1212
pub const MISSING_ARGUMENT: &str = "RS0204";
13+
pub const DUPLICATE_ARGUMENT: &str = "RS0205";
1314
pub const MANAGED_TO_LOCAL: &str = "RS0301";
1415
pub const USE_AFTER_MANAGE: &str = "RS0401";
1516
pub const LOCAL_VALUE_RETAINED: &str = "RS0501";
@@ -231,6 +232,11 @@ static DIAGNOSTIC_EXPLANATIONS: &[DiagnosticExplanation] = &[
231232
title: "missing required argument",
232233
explanation: "Every parameter in the resolved callee signature must be supplied by name at the call site.",
233234
},
235+
DiagnosticExplanation {
236+
code: code::DUPLICATE_ARGUMENT,
237+
title: "duplicate named argument",
238+
explanation: "A call may bind each named parameter only once. Duplicate names make effect and ownership review ambiguous.",
239+
},
234240
DiagnosticExplanation {
235241
code: code::MANAGED_TO_LOCAL,
236242
title: "managed-to-local conversion",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// expect: RS0205
2+
mode: uses-local
3+
4+
struct Image {
5+
pixels: Buffer
6+
}
7+
8+
fn bad_resize_duplicate_argument(path: read Path) -> Unit {
9+
local image = Image.load(path: read path)
10+
Image.resize(image: mut image, image: mut image, width: 800, height: 600)
11+
}

0 commit comments

Comments
 (0)