changelog/v1.7.md
Happy birthday Louis! 🎁
Function captures are now formatted like regular function calls. (Giacomo Cavalieri)
Record updates are now formatted like function calls. (Giacomo Cavalieri)
Fixed a bug where the "convert from use" code action would generate invalid code with labelled arguments. (Giacomo Cavalieri)
Fixed a bug where private types would be allowed to be used in other modules. (Surya Rose)
:bytes segment would give the
wrong pattern match result for a sliced bit array.
(Richard Viney)Removed compiler hint about pattern matching a Result(a, b) when being used
where a is expected.
(Kieran O'Reilly)
Optimised code generated for record updates. (yoshi)
The compiler now allows for record updates to change the generic type parameters of the record:
type Box(value) {
Box(password: String, value: value)
}
fn insert(box: Box(a), value: b) -> Box(b) {
Box(..box, value:)
}
(yoshi)
It is now allowed to write a block with no expressions. Like an empty function
body, an empty block is considered incomplete as if it contained a todo
expression.
(Giacomo Cavalieri)
The shorthand names for the two targets, erl and js are now
deprecated in code such as @target.
(Surya Rose)
A custom panic message can now be specified when asserting a value with
let assert:
let assert Ok(regex) = regex.compile("ab?c+") as "This regex is always valid"
When targeting JavaScript the compiler now generates faster and smaller code
for Int values in bit array expressions and patterns by evaluating them at
compile time where possible.
(Richard Viney)
Qualified records can now be used in clause guards. (Surya Rose)
The compiler now allows deprecating specific custom type variants using the
@deprecated attribute:
pub type HashAlgorithm {
@deprecated("Please upgrade to another algorithm")
Md5
Sha224
Sha512
}
pub fn hash_password(input: String) -> String {
hash(input:, algorithm: Md5) // Warning: Deprecated value used
}
(Iesha)
On the JavaScript target, taking byte-aligned slices of bit arrays is now an O(1) operation instead of O(N), significantly improving performance. (Richard Viney)
Better error message for when an existing type constructor is used as a value constructor. (Jiangda Wang)
Print better error messages when shell commands used by compiler cannot be found. (wheatfox)
Improved the error message you get when trying to add a package that doesn't
exist with gleam add.
(Giacomo Cavalieri)
External files (such as .mjs and .erl) are now permitted in subdirectories
of src/ and test/.
(PgBiel)
gleam publish now requires more verbose confirmation for publishing Gleam
team packages and v0 packages.
(Louis Pilfold)
gleam publish now warns when publishing packages that define multiple
top-level modules, as this can lead to namespace pollution and conflicts for
consumers.
(Aleksei Gurianov)
New projects now require gleam_stdlib v0.44.0.
(Louis Pilfold)
gleam remove no longer requires a network connection.
(yoshi)
Commands that work with the Hex package manager API now create and store an API key rather than creating a new one each time. This API key is encrypted with a local password, reducing risk of your Hex password being compromised. (Louis Pilfold)
The build tool now sets the REBAR_SKIP_PROJECT_PLUGINS environment variable
when using rebar3 to compile Erlang dependencies. With future versions of
rebar3 this will cause it to skip project plugins, significantly reducing the
amount of code it'll need to download and compile, improving compile times.
(Tristan Sloughter)
The language server now provides type information when hovering over argument labels. (Surya Rose)
The language server now suggests a code action to desugar a use expression into the equivalent function call. For example, this snippet of code:
pub fn main() {
use profile <- result.try(fetch_profile(user))
render_welcome(user, profile)
}
Will be turned into:
pub fn main() {
result.try(fetch_profile(user), fn(profile) {
render_welcome(user, profile)
})
}
The language server now suggests a code action to turn a function call into the equivalent use expression. For example, this snippet of code:
pub fn main() {
result.try(fetch_profile(user) fn(profile) {
render_welcome(user, profile)
})
}
Will be turned into:
pub fn main() {
use profile <- result.try(fetch_profile(user))
render_welcome(user, profile)
}
The language server now provides correct information when hovering over patterns in use expressions. (Surya Rose)
The language server now suggests a code action to convert an inexhaustive
let assignment into a case expression:
pub fn unwrap_result(result: Result(a, b)) -> a {
let Ok(inner) = result
inner
}
Becomes:
pub fn unwrap_result(result: Result(a, b)) -> a {
let inner = case result {
Ok(inner) -> inner
Error(_) -> todo
}
inner
}
The language server now provides an action to extract a value into a variable. (Giacomo Cavalieri)
The language server now suggests a code action to expand a function capture into the equivalent anonymous function. For example, this snippet of code:
pub fn main() {
list.map([1, 2, 3], int.add(_, 11))
}
Will be turned into:
pub fn main() {
list.map([1, 2, 3], fn(value) { int.add(value, 11) })
}
The language server now suggests a code action to generate a dynamic decoder for a custom type. For example, this code:
pub type Person {
Person(name: String, age: Int)
}
Will become:
import gleam/dynamic/decode
pub type Person {
Person(name: String, age: Int)
}
fn person_decoder() -> decode.Decoder(Person) {
use name <- decode.field("name", decode.string)
use age <- decode.field("age", decode.int)
decode.success(Person(name:, age:))
}
The formatter now adds a todo inside empty blocks.
(Giacomo Cavalieri)
The formatter now formats lists the same in constants as in expressions. (Jiangda Wang)
The compiler now throws an error when a float literal ends with an e and
is missing an exponent.
(Surya Rose)
Fixed a crash with ENOTEMPTY (os error 39) when building on NTFS partitions. (Ivan Ermakov)
Fixed a bug where the compiler would crash when pattern matching on multiple subjects and one of them being a constant record. (Surya Rose)
Variant inference on prelude types now works correctly if the variant is constant. (Surya Rose)
Fixed a bug where patterns in use expressions would not be checked to ensure
that they were exhaustive.
(Surya Rose)
Fixed a bug where a module.mjs file would be overwritten by a module.gleam
file of same name without warning. It now produces an error.
(PgBiel)
Modules depending on removed or renamed modules now get automatically recompiled. (Sakari Bergen)
The compiler now raises a warning for unused case expressions, code blocks and pipelines that would be safe to remove. (Giacomo Cavalieri)
Fixed a bug where assigning the prefix of a string pattern to a variable nested inside another pattern would produce invalid code on Javascript. (yoshi)
Fixed a bug where expressions which use an unsafe integer on JavaScript would not emit a warning if an external function had been referenced. (Richard Viney)
Fixed a bug where nested tuple access would not be parsed correctly when the left-hand side was a function call. (Surya Rose)
Fixed a bug where Gleam would be unable to compile to BEAM bytecode on older versions of Erlang/OTP. (yoshi)
Fixed a bug where the inferred variant of values was not properly cached, leading to incorrect errors on incremental builds and in the language server. (Surya Rose)
Fixed a bug where Gleam would be unable to compile to BEAM bytecode if the project path contains a non-ascii character. (yoshi)
Fixed a bug where the compiler would display incorrect hints about ignoring unused variables in certain cases. (Surya Rose)
Fixed a bug where the completer would not include braces in type import completions when it should have. (Jiangda Wang)
Fixed a bug where gleam new would generate the github test workflow
configuration with incompatible Erlang OTP and Elixir versions.
(John Strunk)
gleam update would fail to update versions.
(Jason Sipula)