From 2a140e7126947d92c3e07e4a9c5b30024eee3bf9 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sat, 28 Dec 2024 01:34:19 -0300 Subject: [PATCH] Update to Gleam 1.6.3 (#35) * Reset changelog for v1.7 * fix update use_manifest logic * Changelog! * v1.6.1 * Reintroduce exhaustiveness checking for `use` (#3880) * fix: do not use code:del_paths since that function is not available on older versions of Erlang. * switch to conditional compilations instead of a runtime check * Clippy * Clippy, again! * Clippy, again!! * update compiler version * update test name --------- Co-authored-by: Louis Pilfold Co-authored-by: Jason Sipula Co-authored-by: Gears <40563462+GearsDatapacks@users.noreply.github.com> Co-authored-by: yoshi~ --- CHANGELOG.md | 462 +---------------- changelog/v1.6.md | 465 ++++++++++++++++++ compiler-cli/src/dependencies.rs | 4 +- compiler-cli/templates/gleam@@compile.erl | 12 +- .../src/language_server/completer.rs | 2 +- .../src/language_server/tests/completion.rs | 4 +- compiler-core/src/type_/expression.rs | 6 +- compiler-core/src/type_/tests.rs | 12 +- compiler-core/src/type_/tests/errors.rs | 11 + ...rrors__inexhaustive_use_reports_error.snap | 29 ++ compiler-core/src/version.rs | 2 +- 11 files changed, 546 insertions(+), 463 deletions(-) create mode 100644 changelog/v1.6.md create mode 100644 compiler-core/src/type_/tests/snapshots/glistix_core__type___tests__errors__inexhaustive_use_reports_error.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf392358..56e8c6c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,465 +1,37 @@ # Gleam's Changelog -## v1.6.0 - 2024-11-18 -### Bug fixes - -- Fixed a bug where the language server would delete pieces of code when - applying a suggested autocompletion. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -## v1.6.0-rc2 - 2024-11-14 - -### Build tool - -- The version of Erlang used in the GitHub Actions workflow created by - `gleam new` has been increased from v26.0.2 to v27.1.2. - ([Richard Viney](https://github.com/richard-viney)) - -### Bug fixes - -- Fixed a bug where some reserved field names were not properly escaped in - custom types on the JavaScript target. - ([yoshi](https://github.com/joshi-monster)) - -- Fixed a bug where a warning about unsafe integers on the JavaScript target was - emitted when the enclosing function has an external JavaScript implementation. - ([Richard Viney](https://github.com/richard-viney)) - -- Fixed a bug where updating a dependency could break the build cache. - ([yoshi](https://github.com/joshi-monster)) - -- Fixed a bug where if the build directory was not writable then the build tool - would crash when trying to lock the build directory. - ([Zak Farmer](https://github.com/ZakFarmer)) - -## v1.6.0-rc1 - 2024-11-10 - -### Build tool - -- The `--template` flag for `gleam new` takes the values `erlang` and - `javascript` to specify what target to use, with `erlang` being the default. - ([Mohammed Khouni](https://github.com/Tar-Tarus)) - -- The Erlang/Elixir compiler process is now re-used for all packages, shaving - off 0.3-0.5s per compiled package. - ([yoshi](https://github.com/joshi-monster)) - -- When a symlink cannot be made on Windows due to lack of permissions the error - now includes information on how to enable Windows' developer mode, enabling - symlinks. - ([Louis Pilfold](https://github.com/lpil)) - -- The cli can now update individual dependencies. - - `gleam update` and `gleam deps update` now take an optional list of package - names to update: - - ```shell - gleam update package_a - gleam deps update package_b package_c - ``` - - This allows for selective updating of dependencies. When package names are - provided, only those packages and their unique dependencies are unlocked and - updated. If no package names are specified, the command behaves as before, - updating all dependencies. - - ([Jason Sipula](https://github.com/SnakeDoc)) - -- The `repository` config in `gleam.toml` can now optionally include a `path` - so that source links in generated documentation are correct for packages that - aren't located at the root of their repository: - - ```toml - [repository] - type = "github" - user = "gleam-lang" - repo = "gleam" - path = "packages/my_package" - ``` - - ([Richard Viney](https://github.com/richard-viney)) +## Unreleased ### Compiler -- The compiler now prints correctly qualified or aliased type names when - printing type errors. - - This code: - - ```gleam - pub type Int - - pub fn different_int_types(value: Int) { - value - } - - pub fn main() { - different_int_types(20) - } - ``` - - Produces this error: - - ``` - error: Type mismatch - ┌─ /src/wibble.gleam:8:23 - │ - 8 │ different_int_types(20) - │ ^^ - - Expected type: - - Int - - Found type: - - gleam.Int - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) - -- The compiler can now suggest to pattern match on a `Result(a, b)` if it's - being used where a value of type `a` is expected. For example, this code: - - ```gleam - import gleam/list - import gleam/int - - pub fn main() { - let not_a_number = list.first([1, 2, 3]) - int.add(1, not_a_number) - } - ``` - - Results in the following error: - - ```txt - error: Type mismatch - ┌─ /src/one/two.gleam:6:9 - │ - 6 │ int.add(1, not_a_number) - │ ^^^^^^^^^^^^ - - Expected type: - - Int - - Found type: - - Result(Int, a) - - Hint: If you want to get a `Int` out of a `Result(Int, a)` you can pattern - match on it: - - case result { - Ok(value) -> todo - Error(error) -> todo - } - ``` - - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Improved the error message for unknown record fields, displaying an additional - note on how to have a field accessor only if it makes sense. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- The compiler now ignores `optional` dependencies when resolving versions - unless explicitly specified. - ([Gustavo Inacio](https://github.com/gusinacio)) - -- Improved the error message for using `@deprecated` with no deprecation message - ([Jiangda Wang](https://github.com/frank-iii)) - -- Optimised creation of bit arrays on the JavaScript target. - ([Richard Viney](https://github.com/richard-viney)) - -- The compiler can now infer the variant of custom types within expressions that - construct or pattern match on them. - - Using this information it can now be more precise with exhaustiveness - checking, identifying patterns for the other variants as unnecessary. - - ```gleam - pub type Pet { - Dog(name: String, cuteness: Int) - Turtle(name: String, speed: Int, times_renamed: Int) - } - - pub fn main() { - // We know `charlie` is a `Dog`... - let charlie = Dog("Charles", 1000) - - // ...so you do not need to match on the `Turtle` variant - case charlie { - Dog(..) -> todo - } - } - ``` - - This also means that the record update syntax can be used on multi-variant - custom types, so long as the variant can be inferred from the surrounding - code. - - ```gleam - pub fn rename(pet: Pet, to name: String) -> Pet { - case pet { - Dog(..) -> Dog(..pet, name:) - Turtle(..) -> Turtle(..pet, name:, times_renamed: pet.times_renamed + 1) - } - } - ``` - - Variant specific fields can also be used with the accessor syntax. - - ```gleam - pub fn speed(pet: Pet) -> Int { - case pet { - Dog(..) -> 500 - Turtle(..) -> pet.speed - } - } - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) - -- When targeting JavaScript the compiler now emits a warning for integer - literals and constants that lie outside JavaScript's safe integer range: - - ```txt - warning: Int is outside the safe range on JavaScript - ┌─ /Users/richard/Desktop/int_test/src/int_test.gleam:1:15 - │ - 1 │ pub const i = 9_007_199_254_740_992 - │ ^^^^^^^^^^^^^^^^^^^^^ This is not a safe integer on JavaScript - - This integer value is too large to be represented accurately by - JavaScript's number type. To avoid this warning integer values must be in - the range -(2^53 - 1) - (2^53 - 1). - - See JavaScript's Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER - properties for more information. - ``` - - ([Richard Viney](https://github.com/richard-viney)) - -### Formatter - -- The formatter no longer removes the first argument from a function - which is part of a pipeline if the first argument is a capture - and it has a label. This snippet of code is left as is by the formatter: - - ```gleam - pub fn divide(dividend a: Int, divisor b: Int) -> Int { - a / b - } - - pub fn main() { - 10 |> divide(dividend: _, divisor: 2) - } - ``` - - Whereas previously, the label of the capture variable would be lost: - - ```gleam - pub fn divide(dividend a: Int, divisor b: Int) -> Int { - a / b - } - - pub fn main() { - 10 |> divide(divisor: 2) - } - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) +### Build tool ### Language Server -- The Language Server now displays correctly qualified or aliased type names - when hovering over a value in a Gleam file: - - ```gleam - import gleam/option - - const value = option.Some(1) - // ^ hovering here shows `option.Option(Int)` - ``` - - ```gleam - import gleam/option.{type Option as Maybe} - - const value = option.Some(1) - // ^ hovering here shows `Maybe(Int)` - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) - -- The Language Server now suggests a code action to add type annotations to - local variables, constants and functions: - - ```gleam - pub fn add_int_to_float(a, b) { - a +. int.to_float(b) - } - ``` - - Becomes: - - ```gleam - pub fn add_int_to_float(a: Float, b: Int) -> Float { - a +. int.to_float(b) - } - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) - -- The Language Server now suggests a code action to convert qualified imports to - unqualified imports, which updates all occurrences of the qualified name - throughout the module: - - ```gleam - import option - - pub fn main() { - option.Some(1) - } - ``` - - Becomes: - - ```gleam - import option.{Some} - - pub fn main() { - Some(1) - } - ``` - - ([Jiangda Wang](https://github.com/Frank-III)) - -- The Language Server now suggests a code action to convert unqualified imports - to qualified imports, which updates all occurrences of the unqualified name - throughout the module: - - ```gleam - import list.{map} - - pub fn main() { - map([1, 2, 3], fn(x) { x * 2 }) - } - ``` - - Becomes: - - ```gleam - import list.{} - - pub fn main() { - list.map([1, 2, 3], fn(x) { x * 2 }) - } - ``` - - ([Jiangda Wang](https://github.com/Frank-III)) - -### Bug Fixes - -- Fixed a bug in the compiler where shadowing a sized value in a bit pattern - would cause invalid erlang code to be generated. - ([Antonio Iaccarino](https://github.com/eingin)) - -- Fixed a bug where the formatter would not format strings with big grapheme - clusters properly. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed the `BitArray` constructor not being present in the types for the - JavaScript prelude. - ([Richard Viney](https://github.com/richard-viney)) - -- Fixed a bug where generated TypeScript definitions were invalid for opaque - types that use a private type. - ([Richard Viney](https://github.com/richard-viney)) - -- Fixed the prelude re-export in generated TypeScript definitions. - ([Richard Viney](https://github.com/richard-viney)) - -- Fixed a bug where the compiler would incorrectly type-check and compile - calls to functions with labelled arguments in certain cases. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where importing type aliases that reference unimported modules - would generate invalid TypeScript definitions. - ([Richard Viney](https://github.com/richard-viney)) - -- When splitting a constant list made of records, the formatter will keep each - item on its own line to make things easier to read. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed a bug where the compiler would crash when pattern matching on a type - which was defined with duplicate fields in one of its variants. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where the WASM compiler would return incomplete JavaScript when - unsupported features were used. It now returns a compilation error. - ([Richard Viney](https://github.com/richard-viney)) - -- Fixed a bug where incorrect code would be generated for external function on - the Erlang target if any of their arguments were discarded. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed a bug in the error message when using wrong values in a pipe where the - message would swap the "Expected" and "Found" types. - ([Markus Pettersson](https://github.com/MarkusPettersson98/)) - -- Fixed a bug where the parser would incorrectly parse a record constructor with - no arguments. - ([Louis Pilfold](https://github.com/lpil)) - -- Fixed a bug where the parser would incorrectly parse a generic type - constructor with no arguments. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed a bug where the parser would incorrectly parse a generic type definition - with no arguments. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +### Formatter -- Fixed a bug where the language server wouldn't show hints when hovering over - the tail of a list. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +### Bug fix -- Fixed a bug where attempting to jump to the definition of a type from the - annotation of a parameter of an anonymous function would do nothing. - ([Surya Rose](https://github.com/GearsDatapacks)) +## v1.6.3 - 2024-12-03 -- Fixed a bug where referencing record constructors in JavaScript guards but - not calling them could produce invalid code. - ([PgBiel](https://github.com/PgBiel)) +### Bug fixed -- Fixed a bug where using the label shorthand syntax inside of a record update - wouldn't emit a warning when the minimum specified Gleam version was < 1.4.0. +- Fixed a bug where Gleam would be unable to compile to BEAM bytecode on older + versions of Erlang/OTP. ([yoshi](https://github.com/joshi-monster)) -- Fixed a bug where no error would be reported when duplicate labelled - arguments were supplied in a record update. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where an incorrect bit array would be generated on JavaScript for - negative `Int` values when the segment's `size` was wider than 48 bits or when - the `Int` value was less than the minimum representable value for the segment - size. - ([Richard Viney](https://github.com/richard-viney)) +## v1.6.2 - 2024-11-23 -- Fixed a bug where an incorrect `Int` would be returned when pattern matching - to a negative value wider than 48 bits in a bit array. - ([Richard Viney](https://github.com/richard-viney)) +### Bug fixed -- Fixed a bug where unused values coming from other modules wouldn't raise a - warning. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +- Fixed a bug where patterns in `use` expressions would not be checked to ensure that + they were exhaustive. + ([Surya Rose](https://github.com/GearsDatapacks)) -## v1.5.1 - 2024-09-26 +## v1.6.1 - 2024-11-19 -### Bug Fixes +### Bug fix -- Fixed a bug where Erlang file paths would not be escaped on Windows. - ([Louis Pilfold](https://github.com/lpil)) +- Fixed a bug where `gleam update` would fail to update versions. + ([Jason Sipula](https://github.com/SnakeDoc)) diff --git a/changelog/v1.6.md b/changelog/v1.6.md new file mode 100644 index 000000000..b92b3b6a6 --- /dev/null +++ b/changelog/v1.6.md @@ -0,0 +1,465 @@ +# Changelog + +## v1.6.0 - 2024-11-18 + +### Bug fixes + +- Fixed a bug where the language server would delete pieces of code when + applying a suggested autocompletion. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +## v1.6.0-rc2 - 2024-11-14 + +### Build tool + +- The version of Erlang used in the GitHub Actions workflow created by + `gleam new` has been increased from v26.0.2 to v27.1.2. + ([Richard Viney](https://github.com/richard-viney)) + +### Bug fixes + +- Fixed a bug where some reserved field names were not properly escaped in + custom types on the JavaScript target. + ([yoshi](https://github.com/joshi-monster)) + +- Fixed a bug where a warning about unsafe integers on the JavaScript target was + emitted when the enclosing function has an external JavaScript implementation. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where updating a dependency could break the build cache. + ([yoshi](https://github.com/joshi-monster)) + +- Fixed a bug where if the build directory was not writable then the build tool + would crash when trying to lock the build directory. + ([Zak Farmer](https://github.com/ZakFarmer)) + +## v1.6.0-rc1 - 2024-11-10 + +### Build tool + +- The `--template` flag for `gleam new` takes the values `erlang` and + `javascript` to specify what target to use, with `erlang` being the default. + ([Mohammed Khouni](https://github.com/Tar-Tarus)) + +- The Erlang/Elixir compiler process is now re-used for all packages, shaving + off 0.3-0.5s per compiled package. + ([yoshi](https://github.com/joshi-monster)) + +- When a symlink cannot be made on Windows due to lack of permissions the error + now includes information on how to enable Windows' developer mode, enabling + symlinks. + ([Louis Pilfold](https://github.com/lpil)) + +- The cli can now update individual dependencies. + + `gleam update` and `gleam deps update` now take an optional list of package + names to update: + + ```shell + gleam update package_a + gleam deps update package_b package_c + ``` + + This allows for selective updating of dependencies. When package names are + provided, only those packages and their unique dependencies are unlocked and + updated. If no package names are specified, the command behaves as before, + updating all dependencies. + + ([Jason Sipula](https://github.com/SnakeDoc)) + +- The `repository` config in `gleam.toml` can now optionally include a `path` + so that source links in generated documentation are correct for packages that + aren't located at the root of their repository: + + ```toml + [repository] + type = "github" + user = "gleam-lang" + repo = "gleam" + path = "packages/my_package" + ``` + + ([Richard Viney](https://github.com/richard-viney)) + +### Compiler + +- The compiler now prints correctly qualified or aliased type names when + printing type errors. + + This code: + + ```gleam + pub type Int + + pub fn different_int_types(value: Int) { + value + } + + pub fn main() { + different_int_types(20) + } + ``` + + Produces this error: + + ``` + error: Type mismatch + ┌─ /src/wibble.gleam:8:23 + │ + 8 │ different_int_types(20) + │ ^^ + + Expected type: + + Int + + Found type: + + gleam.Int + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +- The compiler can now suggest to pattern match on a `Result(a, b)` if it's + being used where a value of type `a` is expected. For example, this code: + + ```gleam + import gleam/list + import gleam/int + + pub fn main() { + let not_a_number = list.first([1, 2, 3]) + int.add(1, not_a_number) + } + ``` + + Results in the following error: + + ```txt + error: Type mismatch + ┌─ /src/one/two.gleam:6:9 + │ + 6 │ int.add(1, not_a_number) + │ ^^^^^^^^^^^^ + + Expected type: + + Int + + Found type: + + Result(Int, a) + + Hint: If you want to get a `Int` out of a `Result(Int, a)` you can pattern + match on it: + + case result { + Ok(value) -> todo + Error(error) -> todo + } + ``` + + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Improved the error message for unknown record fields, displaying an additional + note on how to have a field accessor only if it makes sense. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- The compiler now ignores `optional` dependencies when resolving versions + unless explicitly specified. + ([Gustavo Inacio](https://github.com/gusinacio)) + +- Improved the error message for using `@deprecated` with no deprecation message + ([Jiangda Wang](https://github.com/frank-iii)) + +- Optimised creation of bit arrays on the JavaScript target. + ([Richard Viney](https://github.com/richard-viney)) + +- The compiler can now infer the variant of custom types within expressions that + construct or pattern match on them. + + Using this information it can now be more precise with exhaustiveness + checking, identifying patterns for the other variants as unnecessary. + + ```gleam + pub type Pet { + Dog(name: String, cuteness: Int) + Turtle(name: String, speed: Int, times_renamed: Int) + } + + pub fn main() { + // We know `charlie` is a `Dog`... + let charlie = Dog("Charles", 1000) + + // ...so you do not need to match on the `Turtle` variant + case charlie { + Dog(..) -> todo + } + } + ``` + + This also means that the record update syntax can be used on multi-variant + custom types, so long as the variant can be inferred from the surrounding + code. + + ```gleam + pub fn rename(pet: Pet, to name: String) -> Pet { + case pet { + Dog(..) -> Dog(..pet, name:) + Turtle(..) -> Turtle(..pet, name:, times_renamed: pet.times_renamed + 1) + } + } + ``` + + Variant specific fields can also be used with the accessor syntax. + + ```gleam + pub fn speed(pet: Pet) -> Int { + case pet { + Dog(..) -> 500 + Turtle(..) -> pet.speed + } + } + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +- When targeting JavaScript the compiler now emits a warning for integer + literals and constants that lie outside JavaScript's safe integer range: + + ```txt + warning: Int is outside the safe range on JavaScript + ┌─ /Users/richard/Desktop/int_test/src/int_test.gleam:1:15 + │ + 1 │ pub const i = 9_007_199_254_740_992 + │ ^^^^^^^^^^^^^^^^^^^^^ This is not a safe integer on JavaScript + + This integer value is too large to be represented accurately by + JavaScript's number type. To avoid this warning integer values must be in + the range -(2^53 - 1) - (2^53 - 1). + + See JavaScript's Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER + properties for more information. + ``` + + ([Richard Viney](https://github.com/richard-viney)) + +### Formatter + +- The formatter no longer removes the first argument from a function + which is part of a pipeline if the first argument is a capture + and it has a label. This snippet of code is left as is by the formatter: + + ```gleam + pub fn divide(dividend a: Int, divisor b: Int) -> Int { + a / b + } + + pub fn main() { + 10 |> divide(dividend: _, divisor: 2) + } + ``` + + Whereas previously, the label of the capture variable would be lost: + + ```gleam + pub fn divide(dividend a: Int, divisor b: Int) -> Int { + a / b + } + + pub fn main() { + 10 |> divide(divisor: 2) + } + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +### Language Server + +- The Language Server now displays correctly qualified or aliased type names + when hovering over a value in a Gleam file: + + ```gleam + import gleam/option + + const value = option.Some(1) + // ^ hovering here shows `option.Option(Int)` + ``` + + ```gleam + import gleam/option.{type Option as Maybe} + + const value = option.Some(1) + // ^ hovering here shows `Maybe(Int)` + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +- The Language Server now suggests a code action to add type annotations to + local variables, constants and functions: + + ```gleam + pub fn add_int_to_float(a, b) { + a +. int.to_float(b) + } + ``` + + Becomes: + + ```gleam + pub fn add_int_to_float(a: Float, b: Int) -> Float { + a +. int.to_float(b) + } + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +- The Language Server now suggests a code action to convert qualified imports to + unqualified imports, which updates all occurrences of the qualified name + throughout the module: + + ```gleam + import option + + pub fn main() { + option.Some(1) + } + ``` + + Becomes: + + ```gleam + import option.{Some} + + pub fn main() { + Some(1) + } + ``` + + ([Jiangda Wang](https://github.com/Frank-III)) + +- The Language Server now suggests a code action to convert unqualified imports + to qualified imports, which updates all occurrences of the unqualified name + throughout the module: + + ```gleam + import list.{map} + + pub fn main() { + map([1, 2, 3], fn(x) { x * 2 }) + } + ``` + + Becomes: + + ```gleam + import list.{} + + pub fn main() { + list.map([1, 2, 3], fn(x) { x * 2 }) + } + ``` + + ([Jiangda Wang](https://github.com/Frank-III)) + +### Bug Fixes + +- Fixed a bug in the compiler where shadowing a sized value in a bit pattern + would cause invalid erlang code to be generated. + ([Antonio Iaccarino](https://github.com/eingin)) + +- Fixed a bug where the formatter would not format strings with big grapheme + clusters properly. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed the `BitArray` constructor not being present in the types for the + JavaScript prelude. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where generated TypeScript definitions were invalid for opaque + types that use a private type. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed the prelude re-export in generated TypeScript definitions. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where the compiler would incorrectly type-check and compile + calls to functions with labelled arguments in certain cases. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where importing type aliases that reference unimported modules + would generate invalid TypeScript definitions. + ([Richard Viney](https://github.com/richard-viney)) + +- When splitting a constant list made of records, the formatter will keep each + item on its own line to make things easier to read. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug where the compiler would crash when pattern matching on a type + which was defined with duplicate fields in one of its variants. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where the WASM compiler would return incomplete JavaScript when + unsupported features were used. It now returns a compilation error. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where incorrect code would be generated for external function on + the Erlang target if any of their arguments were discarded. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug in the error message when using wrong values in a pipe where the + message would swap the "Expected" and "Found" types. + ([Markus Pettersson](https://github.com/MarkusPettersson98/)) + +- Fixed a bug where the parser would incorrectly parse a record constructor with + no arguments. + ([Louis Pilfold](https://github.com/lpil)) + +- Fixed a bug where the parser would incorrectly parse a generic type + constructor with no arguments. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug where the parser would incorrectly parse a generic type definition + with no arguments. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug where the language server wouldn't show hints when hovering over + the tail of a list. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug where attempting to jump to the definition of a type from the + annotation of a parameter of an anonymous function would do nothing. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where referencing record constructors in JavaScript guards but + not calling them could produce invalid code. + ([PgBiel](https://github.com/PgBiel)) + +- Fixed a bug where using the label shorthand syntax inside of a record update + wouldn't emit a warning when the minimum specified Gleam version was < 1.4.0. + ([yoshi](https://github.com/joshi-monster)) + +- Fixed a bug where no error would be reported when duplicate labelled + arguments were supplied in a record update. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where an incorrect bit array would be generated on JavaScript for + negative `Int` values when the segment's `size` was wider than 48 bits or when + the `Int` value was less than the minimum representable value for the segment + size. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where an incorrect `Int` would be returned when pattern matching + to a negative value wider than 48 bits in a bit array. + ([Richard Viney](https://github.com/richard-viney)) + +- Fixed a bug where unused values coming from other modules wouldn't raise a + warning. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +## v1.5.1 - 2024-09-26 + +### Bug Fixes + +- Fixed a bug where Erlang file paths would not be escaped on Windows. + ([Louis Pilfold](https://github.com/lpil)) diff --git a/compiler-cli/src/dependencies.rs b/compiler-cli/src/dependencies.rs index 7bea6872c..845abacd3 100644 --- a/compiler-cli/src/dependencies.rs +++ b/compiler-cli/src/dependencies.rs @@ -117,9 +117,9 @@ pub enum UseManifest { pub fn update(packages: Vec) -> Result<()> { let paths = crate::find_project_paths()?; let use_manifest = if packages.is_empty() { - UseManifest::Yes - } else { UseManifest::No + } else { + UseManifest::Yes }; // Update specific packages diff --git a/compiler-cli/templates/gleam@@compile.erl b/compiler-cli/templates/gleam@@compile.erl index 3e0a645b7..462297610 100644 --- a/compiler-cli/templates/gleam@@compile.erl +++ b/compiler-cli/templates/gleam@@compile.erl @@ -147,10 +147,18 @@ do_compile_elixir(Modules, Out) -> end. add_lib_to_erlang_path(Lib) -> - code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + code:add_paths(expand_lib_paths(Lib)). +-if(?OTP_RELEASE >= 26). del_lib_from_erlang_path(Lib) -> - code:del_paths(filelib:wildcard([Lib, "/*/ebin"])). + code:del_paths(expand_lib_paths(Lib)). +-else. +del_lib_from_erlang_path(Lib) -> + lists:foreach(fun code:del_path/1, expand_lib_paths(Lib)). +-endif. + +expand_lib_paths(Lib) -> + filelib:wildcard([Lib, "/*/ebin"]). configure_logging() -> Enabled = os:getenv("GLEAM_LOG") /= false, diff --git a/compiler-core/src/language_server/completer.rs b/compiler-core/src/language_server/completer.rs index 67f63cb94..554b8a503 100644 --- a/compiler-core/src/language_server/completer.rs +++ b/compiler-core/src/language_server/completer.rs @@ -308,7 +308,7 @@ where } // Get all the modules that can be imported that have not already been imported. - fn completable_modules_for_import(&self) -> Vec<(&EcoString, &ModuleInterface)> { + fn completable_modules_for_import(&'a self) -> Vec<(&'a EcoString, &'a ModuleInterface)> { let mut direct_dep_packages: std::collections::HashSet<&EcoString> = std::collections::HashSet::from_iter( self.compiler.project_compiler.config.dependencies.keys(), diff --git a/compiler-core/src/language_server/tests/completion.rs b/compiler-core/src/language_server/tests/completion.rs index d120ecd3d..b5d3a63da 100644 --- a/compiler-core/src/language_server/tests/completion.rs +++ b/compiler-core/src/language_server/tests/completion.rs @@ -25,8 +25,8 @@ pub fn show_complete(code: &str, position: Position) -> String { fn apply_conversion(src: &str, completions: Vec, value: &str) -> String { let completion = completions .iter() - .find(|c| c.label == value.to_string()) - .expect(&format!("no completion with value `{value}`")); + .find(|c| c.label == *value) + .unwrap_or_else(|| panic!("no completion with value `{value}`")); let mut edits = vec![]; if let Some(lsp_types::CompletionTextEdit::Edit(edit)) = &completion.text_edit { diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index 063521479..a2b08480d 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -1371,10 +1371,8 @@ impl<'a, 'b> ExprTyper<'a, 'b> { // Do not perform exhaustiveness checking if user explicitly used `let assert ... = ...`. let exhaustiveness_check = self.check_let_exhaustiveness(location, value.type_(), &pattern); match (kind, exhaustiveness_check) { - // Generated assignments should be checked before they are generated - (AssignmentKind::Generated, _) => {} - (AssignmentKind::Let, Ok(_)) => {} - (AssignmentKind::Let, Err(e)) => { + (AssignmentKind::Let | AssignmentKind::Generated, Ok(_)) => {} + (AssignmentKind::Let | AssignmentKind::Generated, Err(e)) => { self.problems.error(e); } (AssignmentKind::Assert { location }, Ok(_)) => self diff --git a/compiler-core/src/type_/tests.rs b/compiler-core/src/type_/tests.rs index b79328954..ac3fd023d 100644 --- a/compiler-core/src/type_/tests.rs +++ b/compiler-core/src/type_/tests.rs @@ -256,7 +256,7 @@ macro_rules! assert_warnings_with_imports { vec![ $(("thepackage", $name, $module_src)),* ], - crate::build::Target::Erlang, + $crate::build::Target::Erlang, None ); @@ -272,7 +272,7 @@ macro_rules! assert_warnings_with_imports { #[macro_export] macro_rules! assert_warning { ($src:expr) => { - let warning = $crate::type_::tests::get_printed_warnings($src, vec![], crate::build::Target::Erlang, None); + let warning = $crate::type_::tests::get_printed_warnings($src, vec![], $crate::build::Target::Erlang, None); assert!(!warning.is_empty()); let output = format!("----- SOURCE CODE\n{}\n\n----- WARNING\n{}", $src, warning); insta::assert_snapshot!(insta::internals::AutoName, output, $src); @@ -309,7 +309,7 @@ macro_rules! assert_js_warning { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], - crate::build::Target::JavaScript, + $crate::build::Target::JavaScript, None, ); assert!(!warning.is_empty()); @@ -324,7 +324,7 @@ macro_rules! assert_js_no_warnings { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], - crate::build::Target::JavaScript, + $crate::build::Target::JavaScript, None, ); assert!(warning.is_empty()); @@ -337,7 +337,7 @@ macro_rules! assert_warnings_with_gleam_version { let warning = $crate::type_::tests::get_printed_warnings( $src, vec![], - crate::build::Target::Erlang, + $crate::build::Target::Erlang, Some($gleam_version), ); assert!(!warning.is_empty()); @@ -349,7 +349,7 @@ macro_rules! assert_warnings_with_gleam_version { #[macro_export] macro_rules! assert_no_warnings { ($src:expr $(,)?) => { - let warnings = $crate::type_::tests::get_warnings($src, vec![], crate::build::Target::Erlang, None); + let warnings = $crate::type_::tests::get_warnings($src, vec![], $crate::build::Target::Erlang, None); assert_eq!(warnings, vec![]); }; ($(($package:expr, $name:expr, $module_src:literal)),+, $src:expr $(,)?) => { diff --git a/compiler-core/src/type_/tests/errors.rs b/compiler-core/src/type_/tests/errors.rs index 43a438458..9d6c6a51b 100644 --- a/compiler-core/src/type_/tests/errors.rs +++ b/compiler-core/src/type_/tests/errors.rs @@ -2639,3 +2639,14 @@ pub fn main() { " ); } + +#[test] +// https://github.com/gleam-lang/gleam/issues/3879 +fn inexhaustive_use_reports_error() { + assert_error!( + r#" +use [1, 2, 3] <- todo +todo +"# + ); +} diff --git a/compiler-core/src/type_/tests/snapshots/glistix_core__type___tests__errors__inexhaustive_use_reports_error.snap b/compiler-core/src/type_/tests/snapshots/glistix_core__type___tests__errors__inexhaustive_use_reports_error.snap new file mode 100644 index 000000000..e2d47e9d6 --- /dev/null +++ b/compiler-core/src/type_/tests/snapshots/glistix_core__type___tests__errors__inexhaustive_use_reports_error.snap @@ -0,0 +1,29 @@ +--- +source: compiler-core/src/type_/tests/errors.rs +expression: "\nuse [1, 2, 3] <- todo\ntodo\n" +--- +----- SOURCE CODE + +use [1, 2, 3] <- todo +todo + + +----- ERROR +error: Inexhaustive pattern + ┌─ /src/one/two.gleam:2:5 + │ +2 │ use [1, 2, 3] <- todo + │ ^^^^^^^^^ + +This assignment uses a pattern that does not match all possible values. If +one of the other values is used then the assignment will crash. + +The missing patterns are: + + [] + [_, _, _, _, ..] + [_, _, _] + [_, _] + [_] + +Hint: Use a more general pattern or use `let assert` instead. diff --git a/compiler-core/src/version.rs b/compiler-core/src/version.rs index 4a0af6d27..a67d4af5f 100644 --- a/compiler-core/src/version.rs +++ b/compiler-core/src/version.rs @@ -3,4 +3,4 @@ /// instead build from scratch /// Note that this should be updated to correspond to the Gleam version /// we are basing Glistix on. This is checked by packages. -pub const COMPILER_VERSION: &str = "1.6.0"; +pub const COMPILER_VERSION: &str = "1.6.3";