diff --git a/CHANGELOG.md b/CHANGELOG.md index 475038a76..08bc09c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,482 +1,9 @@ # Gleam's Changelog -## v1.5.0 - 2024-09-19 - -## v1.5.0-rc2 - 2024-09-18 - -### Bug Fixes - -- Fixed a bug where the formatter would not format nested tuple access properly. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed a bug where multi-variant custom type accessors wouldn't be properly - detected. - ([Louis Pilfold](https://github.com/lpil)) - - -## v1.5.0-rc1 - 2024-09-14 - -### Build tool - -- The `--no-print-progress` flag has been added to prevent the build tool from - printing messages as the project is built. - ([Ankit Goel](https://github.com/crazymerlyn)) - -- The compiler is now able to run a dependency's module using `gleam run -m` - even when there's compilation errors in your own project's code. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- HTML docs: make module names in sidebar wrap before a / when possible - ([Jiangda Wang](https://github.com/frank-iii)) - -- The printing of runtime errors has been improved, including those from linked - processes. - ([Louis Pilfold](https://github.com/lpil)) - -- OTP application trees are now shut down gracefully when `main` exits. - ([Louis Pilfold](https://github.com/lpil)) - -- The `gleam fix` command can now update a project's `gleam` version contraint - to make sure it respects the inferred minimum required version. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- The build tool now refuses to publish a project where the `gleam` version - constraint would include a compiler version that doesn't support the features - used by the package. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- If a project doesn't specify a `gleam` version constraint, the build tool will - automatically infer it and add it to the project's `gleam.toml` before - publishing it. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -### Compiler - -- Compiler progress is now printed to stderr, instead of stdout. - ([Victor Kobinski](https://github.com/vkobinski)) - -- It is now possible to omit the `:utf8` option for literal strings used in a - `BitArray` segment. - - ```gleam - <<"Hello", " ", "world">> - ``` - - Is the same as: - - ```gleam - <<"Hello":utf8, " ":utf8, "world":utf8>> - ``` - - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- In inexhaustive pattern match errors the missing variants are now printed - using the correct syntax for the module the error is emitted in, rather than - the module it was defined in. For example, if you had this code: - - ```gleam - import gleam/option - - pub fn main() { - let an_option = option.Some("wibble!") - case an_option { - option.None -> "missing" - } - } - ``` - - The error message would show the qualified `option.Some(_)` as the missing - pattern: - - ```txt - error: Inexhaustive patterns - ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:5:3 - │ - 5 │ ╭ case an_option { - 6 │ │ option.None -> "missing" - 7 │ │ } - │ ╰───^ - - This case expression does not have a pattern for all possible values. If it - is run on one of the values without a pattern then it will crash. - - The missing patterns are: - - option.Some(_) - ``` - - ([Surya Rose](https://github.com/gearsdatapacks)) - -- Anonymous functions that are immediately called with a record or a tuple as an - argument are now inferred correctly without the need to add type annotations. - For example you can now write: - - ```gleam - fn(x) { x.0 }(#(1, 2)) - // ^ you no longer need to annotate this! - ``` - - ([sobolevn](https://github.com/sobolevn)) - -- Anonymous functions that are being piped a record or a tuple as an argument - are now inferred correctly without the need to add type annotations. For - example you can now write: - - ```gleam - pub type User { - User(name: String) - } - - pub fn main() { - User("Giacomo") - |> fn(user) { user.name } - // ^^^^ you no longer need to annotate this! - |> io.debug - } - ``` - - ([sobolevn](https://github.com/sobolevn)) - -- The record pattern matching syntax `Record(a ..)` is now deprecated in favour - of the `Record(a, ..)` syntax. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Adds a better error message when module names are used as values. For example - the following code: - - ```gleam - import gleam/list - - pub fn main() { - list - } - ``` - - Results in the error: - - ```txt - error: Module `list` used as a value - ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:4:3 - │ - 4 │ list - │ ^^^^ - - Modules are not values, so you cannot assign them to variables, pass them to - functions, or anything else that you would do with a value. - ``` - - ([sobolevn](https://github.com/sobolevn)) - -- An helpful error message has been added when the programmer attempts to write - a function within a custom type definition, likely trying to declare an OOP - class. For example: - - ```gleam - pub type User { - User(name: String) - - fn greet(user: User) -> String { - "hello " <> user.name - } - } - ``` - - Now results in the following error: - - ```txt - error: Syntax error - ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:8:3 - │ - 8 │ fn greet(user: User) -> String { - │ ^^ I was not expecting this - - Found the keyword `fn`, expected one of: - - `}` - - a record constructor - Hint: Gleam is not an object oriented programming language so - functions are declared separately from types. - ``` - - ([sobolevn](https://github.com/sobolevn)) - -- The compiler now gives a hint to import a module when accessing modules that - aren't imported. It only suggests a module if it exports a type/value with - the same name as what the user was trying to access: - - ```gleam - pub fn main() { - io.println("Hello, world!") - } - ``` - - Produces the following error: - - ``` - error: Unknown module - ┌─ /src/file.gleam:2:3 - │ - 2 │ io.println("Hello, world!") - │ ^^ - - No module has been found with the name `io`. - Hint: Did you mean to import `gleam/io`? - ``` - - This code, however, produces no hint: - - ```gleam - pub fn main() { - io.non_existent() - } - ``` - - ([Surya Rose](https://github.com/gearsdatapacks)) - -- The compiler now provides improved suggestions in the error for an - inexhaustive case expression. The following code: - - ```gleam - let a = True - case a {} - ``` - - Now produces this error: - - ``` - error: Inexhaustive patterns - ┌─ /src/file.gleam:3:3 - │ - 3 │ case a {} - │ ^^^^^^^^^ - - This case expression does not have a pattern for all possible values. If it - is run on one of the values without a pattern then it will crash. - - The missing patterns are: - - False - True - ``` - - Whereas before, it would suggest `_` as the only missing pattern. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Improve error message for using `@external` with unknown target - ([Jiangda Wang](https://github.com/frank-iii)) - -- Improved error title when using an unknown module value. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- The compiler now shows an helpful error message if you try writing an `if` - expression instead of a case. For example, this code: - - ```gleam - pub fn main() { - let a = if wibble { - 1 - } - } - ``` - - Results in the following error: - - ```txt - error: Syntax error - ┌─ /src/parse/error.gleam:3:11 - │ - 3 │ let a = if wibble { - │ ^^ Gleam doesn't have if expressions - - If you want to write a conditional expression you can use a `case`: - - case condition { - True -> todo - False -> todo - } - - See: https://tour.gleam.run/flow-control/case-expressions/ - ``` - - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- The compiler can now infer the minimum Gleam version needed for your code to - compile and emits a warning if the project's `gleam` version constraint - doesn't include it. - For example, let's say your `gleam.toml` has the constraint - `gleam = ">= 1.1.0"` and your code is using some feature introduced in a later - version: - - ```gleam - // Concatenating constant strings was introduced in v1.4.0! - pub const greeting = "hello " <> "world!" - ``` - - You would now get the following warning: - - ```txt - warning: Incompatible gleam version range - ┌─ /Users/giacomocavalieri/Desktop/datalog/src/datalog.gleam:1:22 - │ - 1 │ pub const greeting = "hello " <> "world!" - │ ^^^^^^^^^^^^^^^^^^^^ This requires a Gleam version >= 1.4.0 - - Constant strings concatenation was introduced in version v1.4.0. But the - Gleam version range specified in your `gleam.toml` would allow this code to - run on an earlier version like v1.1.0, resulting in compilation errors! - Hint: Remove the version constraint from your `gleam.toml` or update it to be: - - gleam = ">= 1.4.0" - ``` - - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- On the JavaScript target, non-byte aligned integers in bit array patterns are - now reported as a compile-time error. - - ([Richard Viney](https://github.com/richard-viney)) - -### Formatter - -- The formatter now adds a `todo` after a `use` expression if it is the last - expression in a block. For example, the following code: - - ```gleam - pub fn main() { - use user <- result.try(fetch_user()) - } - ``` - - Is rewritten as: - - ```gleam - pub fn main() { - use user <- result.try(fetch_user()) - todo - } - ``` - - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -### Language Server - -- The language server can now show completions for local variables inside a function. - ([Ezekiel Grosfeld](https://github.com/ezegros)) - -- The language server can now suggest a code action to assign an unused value to - `_`. - ([Jiangda Wang](https://github.com/frank-iii)) - -- The language server can now suggest a code action to import modules for - existing code which references unimported modules: - - ```gleam - pub fn main() { - io.println("Hello, world!") - } - ``` - - Becomes: - - ```gleam - import gleam/io - - pub fn main() { - io.println("Hello, world!") - } - ``` - - ([Surya Rose](https://github.com/gearsdatapacks)) - -- The Language Server can now suggest a code action to fill in the missing - patterns of a case expression: - - ```gleam - let a = True - case a {} - ``` - - Becomes: - - ```gleam - let a = True - case a { - False -> todo - True -> todo - } - ``` - - ([Surya Rose](https://github.com/GearsDatapacks)) +## v1.5.1 - 2024-09-26 ### Bug Fixes -- Fixed a bug where the warnings were printed above the errors without any new - line between them. - ([Victor Kobinski](https://github.com/vkobinski)) - -- Fixed a bug which caused the language server and compiler to crash when two - constructors of the same name were created. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where jumping to the definition of an unqualified function would - produce the correct location, but remain in the same file. - ([Surya Rose](https://github.com/gearsdatapacks)) - -- Fixed a bug where incorrect syntax error message were shown, when using `:` or - `=` in wrong positions in expressions. - ([Ankit Goel](https://github.com/crazymerlyn)) - -- Fixed a bug where the compiler would crash when pattern matching on a type - which had constructors of duplicate names. - ([Surya Rose](https://github.com/gearsdatapacks)) - -- Fixed a bug where referencing record constructors in JavaScript constants but - not calling them could produce invalid code. +- Fixed a bug where Erlang file paths would not be escaped on Windows. ([Louis Pilfold](https://github.com/lpil)) -- Fixed a bug where source links in HTML documentation would be incorrect for - Codeberg, SourceHut, and Gitea. - ([sobolevn](https://github.com/sobolevn)) - -- Fixed a bug with Erlang code generation for discard utf8 patterns in bit - arrays. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- Fixed a bug which affected inference of function calls in pipe expressions. - ([sobolevn](https://github.com/sobolevn)) - -- Improved an error message when using variable names starting with an - underscore in expression like: `let some = _func()` or `case { 1 -> _func() }` - ([sobolevn](https://github.com/sobolevn)) - -- Fixed a bug where the provided `REBAR_BARE_COMPILER_OUTPUT_DIR` env var would - use relative path instead of absolute path causing compilation errors in some - packages. - ([Gustavo Inacio](https://github.com/gusinacio)) - -- Fixed a bug where the compiler would print incorrect missing patterns for - inexhaustive case expressions matching on more than one subject. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where the compiler would not check the target support of a - function if it was imported and not used, and generate invalid code. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where an qualified unused constructor wouldn't be reported as - unused. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -- The Language Server now correctly shows completions for values in the Gleam - prelude. - ([Surya Rose](https://github.com/GearsDatapacks)) - -- Fixed a bug where the language server wouldn't let you jump to the definition - of a function with an external implementation defined in the same module. - ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) - -## v1.4.1 - 2024-08-04 - -### Bug Fixes - -- Fix a bug that caused record accessors for private types to not be completed - by the LSP, even when in the same module. - ([Ameen Radwan](https://github.com/Acepie)) diff --git a/changelog/v1.5.md b/changelog/v1.5.md new file mode 100644 index 000000000..b993ebf87 --- /dev/null +++ b/changelog/v1.5.md @@ -0,0 +1,482 @@ +# Changelog + +## v1.5.0 - 2024-09-19 + +## v1.5.0-rc2 - 2024-09-18 + +### Bug Fixes + +- Fixed a bug where the formatter would not format nested tuple access properly. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug where multi-variant custom type accessors wouldn't be properly + detected. + ([Louis Pilfold](https://github.com/lpil)) + + +## v1.5.0-rc1 - 2024-09-14 + +### Build tool + +- The `--no-print-progress` flag has been added to prevent the build tool from + printing messages as the project is built. + ([Ankit Goel](https://github.com/crazymerlyn)) + +- The compiler is now able to run a dependency's module using `gleam run -m` + even when there's compilation errors in your own project's code. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- HTML docs: make module names in sidebar wrap before a / when possible + ([Jiangda Wang](https://github.com/frank-iii)) + +- The printing of runtime errors has been improved, including those from linked + processes. + ([Louis Pilfold](https://github.com/lpil)) + +- OTP application trees are now shut down gracefully when `main` exits. + ([Louis Pilfold](https://github.com/lpil)) + +- The `gleam fix` command can now update a project's `gleam` version contraint + to make sure it respects the inferred minimum required version. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- The build tool now refuses to publish a project where the `gleam` version + constraint would include a compiler version that doesn't support the features + used by the package. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- If a project doesn't specify a `gleam` version constraint, the build tool will + automatically infer it and add it to the project's `gleam.toml` before + publishing it. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +### Compiler + +- Compiler progress is now printed to stderr, instead of stdout. + ([Victor Kobinski](https://github.com/vkobinski)) + +- It is now possible to omit the `:utf8` option for literal strings used in a + `BitArray` segment. + + ```gleam + <<"Hello", " ", "world">> + ``` + + Is the same as: + + ```gleam + <<"Hello":utf8, " ":utf8, "world":utf8>> + ``` + + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- In inexhaustive pattern match errors the missing variants are now printed + using the correct syntax for the module the error is emitted in, rather than + the module it was defined in. For example, if you had this code: + + ```gleam + import gleam/option + + pub fn main() { + let an_option = option.Some("wibble!") + case an_option { + option.None -> "missing" + } + } + ``` + + The error message would show the qualified `option.Some(_)` as the missing + pattern: + + ```txt + error: Inexhaustive patterns + ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:5:3 + │ + 5 │ ╭ case an_option { + 6 │ │ option.None -> "missing" + 7 │ │ } + │ ╰───^ + + This case expression does not have a pattern for all possible values. If it + is run on one of the values without a pattern then it will crash. + + The missing patterns are: + + option.Some(_) + ``` + + ([Surya Rose](https://github.com/gearsdatapacks)) + +- Anonymous functions that are immediately called with a record or a tuple as an + argument are now inferred correctly without the need to add type annotations. + For example you can now write: + + ```gleam + fn(x) { x.0 }(#(1, 2)) + // ^ you no longer need to annotate this! + ``` + + ([sobolevn](https://github.com/sobolevn)) + +- Anonymous functions that are being piped a record or a tuple as an argument + are now inferred correctly without the need to add type annotations. For + example you can now write: + + ```gleam + pub type User { + User(name: String) + } + + pub fn main() { + User("Giacomo") + |> fn(user) { user.name } + // ^^^^ you no longer need to annotate this! + |> io.debug + } + ``` + + ([sobolevn](https://github.com/sobolevn)) + +- The record pattern matching syntax `Record(a ..)` is now deprecated in favour + of the `Record(a, ..)` syntax. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Adds a better error message when module names are used as values. For example + the following code: + + ```gleam + import gleam/list + + pub fn main() { + list + } + ``` + + Results in the error: + + ```txt + error: Module `list` used as a value + ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:4:3 + │ + 4 │ list + │ ^^^^ + + Modules are not values, so you cannot assign them to variables, pass them to + functions, or anything else that you would do with a value. + ``` + + ([sobolevn](https://github.com/sobolevn)) + +- An helpful error message has been added when the programmer attempts to write + a function within a custom type definition, likely trying to declare an OOP + class. For example: + + ```gleam + pub type User { + User(name: String) + + fn greet(user: User) -> String { + "hello " <> user.name + } + } + ``` + + Now results in the following error: + + ```txt + error: Syntax error + ┌─ /Users/giacomocavalieri/Desktop/prova/src/prova.gleam:8:3 + │ + 8 │ fn greet(user: User) -> String { + │ ^^ I was not expecting this + + Found the keyword `fn`, expected one of: + - `}` + - a record constructor + Hint: Gleam is not an object oriented programming language so + functions are declared separately from types. + ``` + + ([sobolevn](https://github.com/sobolevn)) + +- The compiler now gives a hint to import a module when accessing modules that + aren't imported. It only suggests a module if it exports a type/value with + the same name as what the user was trying to access: + + ```gleam + pub fn main() { + io.println("Hello, world!") + } + ``` + + Produces the following error: + + ``` + error: Unknown module + ┌─ /src/file.gleam:2:3 + │ + 2 │ io.println("Hello, world!") + │ ^^ + + No module has been found with the name `io`. + Hint: Did you mean to import `gleam/io`? + ``` + + This code, however, produces no hint: + + ```gleam + pub fn main() { + io.non_existent() + } + ``` + + ([Surya Rose](https://github.com/gearsdatapacks)) + +- The compiler now provides improved suggestions in the error for an + inexhaustive case expression. The following code: + + ```gleam + let a = True + case a {} + ``` + + Now produces this error: + + ``` + error: Inexhaustive patterns + ┌─ /src/file.gleam:3:3 + │ + 3 │ case a {} + │ ^^^^^^^^^ + + This case expression does not have a pattern for all possible values. If it + is run on one of the values without a pattern then it will crash. + + The missing patterns are: + + False + True + ``` + + Whereas before, it would suggest `_` as the only missing pattern. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Improve error message for using `@external` with unknown target + ([Jiangda Wang](https://github.com/frank-iii)) + +- Improved error title when using an unknown module value. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- The compiler now shows an helpful error message if you try writing an `if` + expression instead of a case. For example, this code: + + ```gleam + pub fn main() { + let a = if wibble { + 1 + } + } + ``` + + Results in the following error: + + ```txt + error: Syntax error + ┌─ /src/parse/error.gleam:3:11 + │ + 3 │ let a = if wibble { + │ ^^ Gleam doesn't have if expressions + + If you want to write a conditional expression you can use a `case`: + + case condition { + True -> todo + False -> todo + } + + See: https://tour.gleam.run/flow-control/case-expressions/ + ``` + + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- The compiler can now infer the minimum Gleam version needed for your code to + compile and emits a warning if the project's `gleam` version constraint + doesn't include it. + For example, let's say your `gleam.toml` has the constraint + `gleam = ">= 1.1.0"` and your code is using some feature introduced in a later + version: + + ```gleam + // Concatenating constant strings was introduced in v1.4.0! + pub const greeting = "hello " <> "world!" + ``` + + You would now get the following warning: + + ```txt + warning: Incompatible gleam version range + ┌─ /Users/giacomocavalieri/Desktop/datalog/src/datalog.gleam:1:22 + │ + 1 │ pub const greeting = "hello " <> "world!" + │ ^^^^^^^^^^^^^^^^^^^^ This requires a Gleam version >= 1.4.0 + + Constant strings concatenation was introduced in version v1.4.0. But the + Gleam version range specified in your `gleam.toml` would allow this code to + run on an earlier version like v1.1.0, resulting in compilation errors! + Hint: Remove the version constraint from your `gleam.toml` or update it to be: + + gleam = ">= 1.4.0" + ``` + + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- On the JavaScript target, non-byte aligned integers in bit array patterns are + now reported as a compile-time error. + + ([Richard Viney](https://github.com/richard-viney)) + +### Formatter + +- The formatter now adds a `todo` after a `use` expression if it is the last + expression in a block. For example, the following code: + + ```gleam + pub fn main() { + use user <- result.try(fetch_user()) + } + ``` + + Is rewritten as: + + ```gleam + pub fn main() { + use user <- result.try(fetch_user()) + todo + } + ``` + + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +### Language Server + +- The language server can now show completions for local variables inside a function. + ([Ezekiel Grosfeld](https://github.com/ezegros)) + +- The language server can now suggest a code action to assign an unused value to + `_`. + ([Jiangda Wang](https://github.com/frank-iii)) + +- The language server can now suggest a code action to import modules for + existing code which references unimported modules: + + ```gleam + pub fn main() { + io.println("Hello, world!") + } + ``` + + Becomes: + + ```gleam + import gleam/io + + pub fn main() { + io.println("Hello, world!") + } + ``` + + ([Surya Rose](https://github.com/gearsdatapacks)) + +- The Language Server can now suggest a code action to fill in the missing + patterns of a case expression: + + ```gleam + let a = True + case a {} + ``` + + Becomes: + + ```gleam + let a = True + case a { + False -> todo + True -> todo + } + ``` + + ([Surya Rose](https://github.com/GearsDatapacks)) + +### Bug Fixes + +- Fixed a bug where the warnings were printed above the errors without any new + line between them. + ([Victor Kobinski](https://github.com/vkobinski)) + +- Fixed a bug which caused the language server and compiler to crash when two + constructors of the same name were created. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where jumping to the definition of an unqualified function would + produce the correct location, but remain in the same file. + ([Surya Rose](https://github.com/gearsdatapacks)) + +- Fixed a bug where incorrect syntax error message were shown, when using `:` or + `=` in wrong positions in expressions. + ([Ankit Goel](https://github.com/crazymerlyn)) + +- Fixed a bug where the compiler would crash when pattern matching on a type + which had constructors of duplicate names. + ([Surya Rose](https://github.com/gearsdatapacks)) + +- Fixed a bug where referencing record constructors in JavaScript constants but + not calling them could produce invalid code. + ([Louis Pilfold](https://github.com/lpil)) + +- Fixed a bug where source links in HTML documentation would be incorrect for + Codeberg, SourceHut, and Gitea. + ([sobolevn](https://github.com/sobolevn)) + +- Fixed a bug with Erlang code generation for discard utf8 patterns in bit + arrays. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- Fixed a bug which affected inference of function calls in pipe expressions. + ([sobolevn](https://github.com/sobolevn)) + +- Improved an error message when using variable names starting with an + underscore in expression like: `let some = _func()` or `case { 1 -> _func() }` + ([sobolevn](https://github.com/sobolevn)) + +- Fixed a bug where the provided `REBAR_BARE_COMPILER_OUTPUT_DIR` env var would + use relative path instead of absolute path causing compilation errors in some + packages. + ([Gustavo Inacio](https://github.com/gusinacio)) + +- Fixed a bug where the compiler would print incorrect missing patterns for + inexhaustive case expressions matching on more than one subject. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where the compiler would not check the target support of a + function if it was imported and not used, and generate invalid code. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where an qualified unused constructor wouldn't be reported as + unused. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- The Language Server now correctly shows completions for values in the Gleam + prelude. + ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where the language server wouldn't let you jump to the definition + of a function with an external implementation defined in the same module. + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +## v1.4.1 - 2024-08-04 + +### Bug Fixes + +- Fix a bug that caused record accessors for private types to not be completed + by the LSP, even when in the same module. + ([Ameen Radwan](https://github.com/Acepie)) diff --git a/compiler-core/src/erlang.rs b/compiler-core/src/erlang.rs index fe74810c3..cced29829 100644 --- a/compiler-core/src/erlang.rs +++ b/compiler-core/src/erlang.rs @@ -437,6 +437,7 @@ fn file_attribute<'a>( line_numbers: &'a LineNumbers, ) -> Document<'a> { let line = line_numbers.line_number(function.location.start); + let path = path.replace("\\", "\\\\"); docvec!["-file(\"", path, "\", ", line, ")."] } diff --git a/compiler-core/src/erlang/snapshots/glistix_core__erlang__tests__windows_file_escaping_bug.snap b/compiler-core/src/erlang/snapshots/glistix_core__erlang__tests__windows_file_escaping_bug.snap new file mode 100644 index 000000000..5b885fb5f --- /dev/null +++ b/compiler-core/src/erlang/snapshots/glistix_core__erlang__tests__windows_file_escaping_bug.snap @@ -0,0 +1,14 @@ +--- +source: compiler-core/src/erlang/tests.rs +assertion_line: 944 +expression: "pub fn main() { Nil }" +--- +-module(my@mod). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-file("C:\\root\\project\\test\\my\\mod.gleam", 1). +-spec main() -> nil. +main() -> + nil. diff --git a/compiler-core/src/erlang/tests.rs b/compiler-core/src/erlang/tests.rs index ade270e7e..c5add336f 100644 --- a/compiler-core/src/erlang/tests.rs +++ b/compiler-core/src/erlang/tests.rs @@ -33,7 +33,7 @@ mod type_params; mod use_; mod variables; -pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> String { +pub fn compile_test_project(src: &str, src_path: &str, dep: Option<(&str, &str, &str)>) -> String { let mut modules = im::HashMap::new(); let ids = UniqueIdGenerator::new(); // DUPE: preludeinsertion @@ -73,7 +73,7 @@ pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> Strin let _ = modules.insert(dep_name.into(), dep.type_info); let _ = direct_dependencies.insert(dep_package.into(), ()); } - let path = Utf8PathBuf::from("/root/project/test/my/mod.gleam"); + let path = Utf8PathBuf::from(src_path); let parsed = crate::parse::parse_module(path.clone(), src, &WarningEmitter::null()) .expect("syntax error"); let mut config = PackageConfig::default(); @@ -102,13 +102,18 @@ macro_rules! assert_erl { (($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{ let output = $crate::erlang::tests::compile_test_project( $src, + "/root/project/test/my/mod.gleam", Some(($dep_package, $dep_name, $dep_src)), ); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; ($src:expr $(,)?) => {{ - let output = $crate::erlang::tests::compile_test_project($src, None); + let output = $crate::erlang::tests::compile_test_project( + $src, + "/root/project/test/my/mod.gleam", + None, + ); insta::assert_snapshot!(insta::internals::AutoName, output, $src); }}; } @@ -929,3 +934,12 @@ pub fn main() { " ); } + +// https://github.com/gleam-lang/gleam/issues/3648 +#[test] +fn windows_file_escaping_bug() { + let src = "pub fn main() { Nil }"; + let path = "C:\\root\\project\\test\\my\\mod.gleam"; + let output = compile_test_project(src, path, None); + insta::assert_snapshot!(insta::internals::AutoName, output, src); +} diff --git a/compiler-core/src/version.rs b/compiler-core/src/version.rs index 912cb0a6d..f3f8079b2 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.5.0"; +pub const COMPILER_VERSION: &str = "1.5.1"; diff --git a/test-package-compiler/src/lib.rs b/test-package-compiler/src/lib.rs index dbd3560ea..af60f7d92 100644 --- a/test-package-compiler/src/lib.rs +++ b/test-package-compiler/src/lib.rs @@ -134,7 +134,11 @@ impl TestCompileOutput { Regex::new(r#"-file\("([^"]+)", (\d+)\)\."#).expect("Invalid regex") }) .replace_all(text, |caps: ®ex::Captures| { - let path = caps.get(1).expect("file path").as_str().replace("\\", "/"); + let path = caps + .get(1) + .expect("file path") + .as_str() + .replace("\\\\", "/"); let line_number = caps.get(2).expect("line number").as_str(); format!("-file(\"{}\", {}).", path, line_number) });