Changelog#
Unreleased#
Compiler#
-
On the JavaScript target, bit arrays can now use the
unitoption to control the units of thesizeoption. (Surya Rose) -
The compiler can now tell if string branches are unreachable. For example, the following code:
case a_string { "Hello, " <> name -> name "Hello, Jak" -> "Jak" _ -> "Stranger" }Will raise the following warning:
warning: Unreachable case clause ┌─ /src/greet.gleam:7:5 │ 7 │ "Hello, Jak" -> "Jak" │ ^^^^^^^^^^^^^^^^^^^^^ This case clause cannot be reached as a previous clause matches the same values. Hint: It can be safely removed. -
On the JavaScript target, blocks and various other expressions no longer compile to immediately invoked function expressions. (Surya Rose)
-
On the JavaScript target, bit arrays can now use 16-bit floats in expressions and patterns. (Richard Viney)
-
Improve the error messages for unknown and missing target names in target attributes. (Alexander Keleschovsky)
-
Fixed a bug where a temporarily moved or removed file does not get recompiled, even though its dependencies changed in the meanwhile. (Sakari Bergen)
-
The compiler now uses a call graph for detecting unused types and values. This means that among other things, it can now detect unused recursive functions. For example:
// warning: unused fn some_recursive_function() { some_recursive_function() } -
The compiler now emits a warning when using
let assertto assert a value whose variant has already been inferred. For example:// warning: This will always crash let assert Ok(_) = Error("Some error") -
It is now possible to omit the
:floatoption for literal floats used in aBitArraysegment.<<1.11>>Is the same as:
<<1.11:float>>
Build tool#
-
Include a type annotation for the
mainfunction generated bygleam new. (Drew Olson) -
Two entry point scripts are now always generated by
gleam export erlang-shipment:entrypoint.shfor POSIX Shellentrypoint.ps1for PowerShell (Greg Burri)
-
gleam exportnow takes apackage-informationoption to export the project'sgleam.tomlas a JSON file. (Rodrigo Álvarez) -
Improve error messages when encrypting and decrypting local Hex API key. (Samuel Cristobal)
Language server#
-
The language server now allows renaming of functions, constants, custom type variants and custom types across modules. For example:
// wibble.gleam pub fn wibble() { wibble() //^ Trigger rename } // wobble.gleam import wibble pub fn main() { wibble.wibble() }Becomes:
// wibble.gleam pub fn wobble() { wobble() } // wobble.gleam import wibble pub fn main() { wibble.wobble() } -
The language server can now offer a code action to replace a
..in a pattern with all the fields that are being ignored. For example triggering the code action on this spread:pub type Pokemon { Pokemon(id: Int, name: String, moves: List(String)) } pub fn main() { let Pokemon(..) = todo // ^ If you put your cursor here }Would generate the following code:
pub type Pokemon { Pokemon(id: Int, name: String, moves: List(String)) } pub fn main() { let Pokemon(id:, name:, moves:) = todo } -
The function generated by the "Generate JSON encoder" code action has been slightly modified so that it will now fail to compile if the type has new fields added, ensuring the programmer remembers to re-run the code action. For example, for this type:
type Person { Person(name: String, age: Int) }The following code used to be generated:
fn encode_person(person: Person) -> json.Json { json.object([ #("name", json.string(person.name)), #("age", json.int(person.age)), ]) }But now, this code is generated:
fn encode_person(person: Person) -> json.Json { let Person(name:, age:) = person json.object([ #("name", json.string(name)), #("age", json.int(age)), ]) } -
The language server now supports finding references to values and types, both within a module and across multiple modules. (Surya Rose)
-
The language server now offers a code action to remove all
echos in a module. For example:pub fn main() { [1, 2, 3] |> echo // ^^^^ If you put your cursor over here |> list.filter(int.is_even) |> echo }Triggering the code action would remove all the
echopipeline steps:pub fn main() { [1, 2, 3] |> list.filter(int.is_even) }This also works with all the
echos used before an expression:pub fn main() { echo 1 + 2 //^^^^^^^^^^ If hovering anywhere over here }Triggering the code action would remove the
echo:pub fn main() { 1 + 2 } -
The language server now offers the option to lift expressions into consts. For example, in two uses of the code action:
pub fn main() { [#("a", 0), #("b", 1), #("a", 2)] |> key_filter("a") }Becomes:
const values = [#("a", 0), #("b", 1), #("a", 2)] const string = "a" pub fn main() { values |> key_filter(string) } -
The language server will now only offer the code action to generate a JSON encoder if the
gleam_jsonpackage is installed as a dependency. (Surya Rose)
Formatter#
Bug fixes#
-
Fixed a bug where tuples with atoms in the first position could be incorrectly formatted by
echo. (Louis Pilfold) -
Fixed a bug where unlabelled arguments would be allowed after labelled arguments in variant constructor definitions. (Surya Rose)
-
Fixed a bug where using the "Convert to pipe" code action on a function whose first argument is itself a pipe would result in invalid code. (Giacomo Cavalieri)
-
Fixed a bug where using the "Convert to pipe" code action on a function or record capture produces invalid code. (Matias Carlander)
-
Fixed a bug where the "Inline variable" code action would not work properly if used inside a record update. (Surya Rose)
-
Fixed a bug where variant inference wouldn't work on
let assertassignments. (Giacomo Cavalieri) -
Fixed a bug where the build tool could fail to lock the build directory but not report an error. (Louis Pilfold)
-
Fixed a bug where the language server would be too eager to recompile modules when it could use the cache from previous compilations. (Louis Pilfold)
-
Fixed a bug where
let assertwould not assert that the given value matched the pattern if it was the only expression inside a block. (Surya Rose) -
Fixed a bug where the code generated for
echoon JavaScript could have name collisions if there are functions calledconsoleorprocess, or custom type variants calledObjectorDenodefined in the module. (Louis Pilfold)
v1.9.1 - 2025-03-10#
Formatter#
- Improved the formatting of pipelines printed with
echo. (Giacomo Cavalieri)
Bug fixes#
- Fixed a bug where
echoused before a pipeline would generate invalid code for the Erlang target. (Giacomo Cavalieri)