Skip to content

Commit 21e9b91

Browse files
seafoamteallpil
authored andcommitted
Avoid showing error at record usage site
Since the user can already see the error at the type definition site, showing errors wherver the type is used will be confusing for them.
1 parent 787aa36 commit 21e9b91

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

compiler-core/src/type_/expression.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,13 +3256,14 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
32563256
// all correspond to positional fields. If this is not the case, then the
32573257
// user currently has a mistake in the definition of their custom type.
32583258
//
3259-
// For example, when a user starts adding a new labelled field to a custom
3260-
// type constructor, the field label will be parsed as a custom type name
3261-
// until they type the colon i.e. as a new positional field.
3262-
let type_ = positional_fields
3263-
.get(index as usize)
3264-
.ok_or_else(|| Error::UnlabelledAfterlabelled { location })?
3265-
.clone();
3259+
// However, we do not want to show an error here, because it would be
3260+
// confusing for the programmer. They can already see the error at the type
3261+
// definition site.
3262+
let type_ = if let Some(type_) = positional_fields.get(index as usize) {
3263+
type_.clone()
3264+
} else {
3265+
continue;
3266+
};
32663267

32673268
let mut type_vars = im::HashMap::new();
32683269
let accessor_type = self.instantiate(accessor_type, &mut type_vars);

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__no_crash_on_record_update_when_constructor_definition_is_invalid.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ error: Unlabelled argument after labelled argument
2222
│ ^^^^
2323

2424
All unlabelled arguments must come before any labelled arguments.
25-
26-
error: Unlabelled argument after labelled argument
27-
┌─ /src/one/two.gleam:8:13
28-
29-
8let two = Wibble(..one, b: 1)
30-
^^^^^^^^^^^^^^^^^^^
31-
32-
All unlabelled arguments must come before any labelled arguments.

0 commit comments

Comments
 (0)