diff --git a/CHANGELOG.md b/CHANGELOG.md index b292c688c0b..8999f6f1ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ used on a variable followed by a case expression. ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +- Fixed a bug where the record field is forgotten by compiler when its + type is not valid. + ([Adi Salimgereyev](https://github.com/abs0luty)) + ## v1.13.0-rc1 - 2025-09-29 ### Compiler diff --git a/compiler-core/src/analyse.rs b/compiler-core/src/analyse.rs index c94141b5b11..b3226eeff92 100644 --- a/compiler-core/src/analyse.rs +++ b/compiler-core/src/analyse.rs @@ -1121,7 +1121,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> { Ok(t) => t, Err(e) => { self.problems.error(e); - continue; + environment.new_unbound_var() } }; diff --git a/compiler-core/src/type_/tests/errors.rs b/compiler-core/src/type_/tests/errors.rs index 37084a6e083..c66795e3e51 100644 --- a/compiler-core/src/type_/tests/errors.rs +++ b/compiler-core/src/type_/tests/errors.rs @@ -3345,3 +3345,24 @@ fn type_used_as_a_constructor_with_more_arguments() { }" ); } + +#[test] +fn remembering_record_field_when_type_checking_fails() { + assert_module_error!( + r#"pub type Wibble { + Wibble(x: Int, f: fn(Wobble) -> Int) +} + +pub fn wibble() { + Wibble(1, fn(_) { 2 }) +} + +pub fn wobble(wibble: Wibble) { + wibble.f +} + +pub fn woo(wibble: Wibble) { + Wibble(..wibble, x: 1) +}"# + ); +} diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__remembering_record_field_when_type_checking_fails.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__remembering_record_field_when_type_checking_fails.snap new file mode 100644 index 00000000000..a473085265c --- /dev/null +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__errors__remembering_record_field_when_type_checking_fails.snap @@ -0,0 +1,29 @@ +--- +source: compiler-core/src/type_/tests/errors.rs +expression: "pub type Wibble {\n Wibble(x: Int, f: fn(Wobble) -> Int)\n}\n\npub fn wibble() {\n Wibble(1, fn(_) { 2 })\n}\n\npub fn wobble(wibble: Wibble) {\n wibble.f\n}\n\npub fn woo(wibble: Wibble) {\n Wibble(..wibble, x: 1)\n}" +--- +----- SOURCE CODE +pub type Wibble { + Wibble(x: Int, f: fn(Wobble) -> Int) +} + +pub fn wibble() { + Wibble(1, fn(_) { 2 }) +} + +pub fn wobble(wibble: Wibble) { + wibble.f +} + +pub fn woo(wibble: Wibble) { + Wibble(..wibble, x: 1) +} + +----- ERROR +error: Unknown type + ┌─ /src/one/two.gleam:2:24 + │ +2 │ Wibble(x: Int, f: fn(Wobble) -> Int) + │ ^^^^^^ Did you mean `Wibble`? + +The type `Wobble` is not defined or imported in this module. diff --git a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__exhaustiveness__reference_absent_type.snap b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__exhaustiveness__reference_absent_type.snap index 736d885caaf..56c9ffbb168 100644 --- a/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__exhaustiveness__reference_absent_type.snap +++ b/compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__exhaustiveness__reference_absent_type.snap @@ -50,4 +50,4 @@ is run on one of the values without a pattern then it will crash. The missing patterns are: - Two + Two(_)