+2
-13
compiler-core/src/type_/fields.rs
+2
-13
compiler-core/src/type_/fields.rs
···
55
55
56
56
if self.arity as usize != args.len() {
57
57
return Err(Error::IncorrectArity {
58
-
labels: self.incorrect_arity_labels(args),
58
+
labels: self.missing_labels(args),
59
59
location,
60
60
context,
61
61
expected: self.arity as usize,
···
145
145
}
146
146
}
147
147
148
-
pub fn incorrect_arity_labels<A>(&self, args: &[CallArg<A>]) -> Vec<EcoString> {
149
-
let given: HashSet<_> = args.iter().filter_map(|arg| arg.label.as_ref()).collect();
150
-
151
-
self.fields
152
-
.keys()
153
-
.filter(|f| !given.contains(f))
154
-
.cloned()
155
-
.sorted()
156
-
.collect()
157
-
}
158
-
159
148
/// This returns an array of the labels that are unused given an argument
160
149
/// list.
161
150
/// The unused labels are in the order they are expected to be passed in
···
169
158
/// wibble(1, label3: 2) // -> unused labels: [label2]
170
159
/// ```
171
160
///
172
-
pub fn missing_labels<A: std::fmt::Debug>(&self, args: &[CallArg<A>]) -> Vec<EcoString> {
161
+
pub fn missing_labels<A>(&self, args: &[CallArg<A>]) -> Vec<EcoString> {
173
162
// We need to know how many positional arguments are in the function
174
163
// arguments. That's given by the position of the first labelled
175
164
// argument; if the first label argument is third, then we know the
+16
compiler-core/src/type_/tests/errors.rs
+16
compiler-core/src/type_/tests/errors.rs
···
3208
3208
"
3209
3209
);
3210
3210
}
3211
+
3212
+
// https://github.com/gleam-lang/gleam/issues/3884
3213
+
#[test]
3214
+
fn show_only_missing_labels() {
3215
+
assert_module_error!(
3216
+
"
3217
+
fn wibble(a a: Int, b b: Float, c c: String) {
3218
+
todo
3219
+
}
3220
+
3221
+
pub fn wobble() {
3222
+
wibble(1, 2.0)
3223
+
}
3224
+
"
3225
+
);
3226
+
}
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__guard_record_wrong_arity.snap
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__guard_record_wrong_arity.snap
+25
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__show_only_missing_labels.snap
+25
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__show_only_missing_labels.snap
···
1
+
---
2
+
source: compiler-core/src/type_/tests/errors.rs
3
+
expression: "\nfn wibble(a a: Int, b b: Float, c c: String) {\n todo\n}\n\npub fn wobble() {\n wibble(1, 2.0)\n}\n"
4
+
---
5
+
----- SOURCE CODE
6
+
7
+
fn wibble(a a: Int, b b: Float, c c: String) {
8
+
todo
9
+
}
10
+
11
+
pub fn wobble() {
12
+
wibble(1, 2.0)
13
+
}
14
+
15
+
16
+
----- ERROR
17
+
error: Incorrect arity
18
+
┌─ /src/one/two.gleam:7:5
19
+
│
20
+
7 │ wibble(1, 2.0)
21
+
│ ^^^^^^^^^^^^^^ Expected 3 arguments, got 2
22
+
23
+
This call accepts these additional labelled arguments:
24
+
25
+
- c
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__functions__function_call_incorrect_arity_with_label_shorthand_fault_tolerance2.snap
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__functions__function_call_incorrect_arity_with_label_shorthand_fault_tolerance2.snap
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__functions__function_call_incorrect_arity_with_labels_fault_tolerance2.snap
-1
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__functions__function_call_incorrect_arity_with_labels_fault_tolerance2.snap