Fork of daniellemaywood.uk/gleam — Wasm codegen work
18 kB
650 lines
1<!--
2 SPDX-License-Identifier: Apache-2.0
3 SPDX-FileCopyrightText: 2020 The Gleam contributors
4-->
5
6# Changelog
7
8## Unreleased
9
10### Bug fixes
11
12- Fixed a bug where the compiler would crash when wrapping an error message
13 whose line broke in the middle of a multi-byte UTF-8 character.
14 ([John Downey](https://github.com/jtdowney))
15
16- Fixed a bug where invalid JavaScript would be generated for code which used a
17 bit array pattern to extract a `Float` and had a constructor called `Number`.
18 ([Surya Rose](https://github.com/GearsDatapacks))
19
20- Fixed a bug where `-0.0` would be encoded incorrectly in 16-bit bit array
21 segments on the JavaScript target.
22 ([Surya Rose](https://github.com/GearsDatapacks))
23
24- Fixed a bug where the formatter would insert underscores into negative
25 hexadecimal, octal, and binary literals, producing code that no longer
26 compiles.
27 ([John Downey](https://github.com/jtdowney))
28
29- Fixed a bug where type annotations on discarded variables in `use` bindings
30 were ignored.
31 ([Francesco Cappetti](https://github.com/frakappa))
32
33## v1.18.0-rc1 - 2026-07-21
34
35### Compiler
36
37- The compiler now issues a friendlier error when attempting to pattern match
38 on both the prefix and suffix of a string:
39
40 ```
41 error: Syntax error
42 ┌─ /src/parse/error.gleam:2:23
43 │
44 2 │ "prefix" <> infix <> "suffix" -> infix
45 │ ^^^^^^^^^^^ This pattern is not allowed
46
47 A string pattern can only match on a literal string prefix.
48
49 Matching on a literal suffix is not possible, because `infix` would have an
50 unknown size.
51 ```
52
53 ([Gavin Morrow](https://github.com/gavinmorrow))
54
55- Improved the error message shown when using an invalid discard name for
56 functions, constants, module names, and `as` patterns.
57 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
58
59- The compiler now generates singleton values for variants with no fields on the
60 JavaScript target, allowing for faster comparison in most cases.
61 ([Surya Rose](https://github.com/GearsDatapacks))
62
63- The use of pipes to turn the Gleam code `a |> b(c)` into `b(c)(a)` has been
64 deprecated.
65 ([Surya Rose](https://github.com/GearsDatapacks))
66
67- The compiler now gives a better error message when an `@external`
68 attribute is incomplete. For example:
69
70 ```gleam
71 @external
72 pub fn wibble()
73 ```
74
75 now points to the attribute itself and explains that it is incomplete.
76 ([Asish Kumar](https://github.com/officialasishkumar))
77
78- The "did you mean one of these:" hint is now phrased in singular when there
79 is only one suggestion, additionally multiple suggestions are listed
80 in a consistent alphabetical order.
81 ([Zbyněk Juřica](https://github.com/zbyju))
82
83### Build tool
84
85- The build tool now generates Hexdocs URLs using the new format of
86 `package.hexdocs.pm` rather than `hexdocs.pm/package`.
87 ([Surya Rose](https://github.com/GearsDatapacks))
88
89- More readable error message when trying to revert an old release.
90 ([Moritz Böhme](https://github.com/MoritzBoehme))
91
92- The build tool now includes destination path in the error when it fails to
93 link or copy file or directory.
94 ([Andrey Kozhev](https://github.com/ankddev))
95
96- Git dependencies now support an optional `path` field to specify a
97 subdirectory within the repository. This is useful for monorepos that
98 contain multiple Gleam packages. For example:
99
100 ```toml
101 [dependencies]
102 my_package = {
103 git = "https://github.com/example/monorepo",
104 ref = "main",
105 path = "packages/my_package",
106 }
107 ```
108
109 ([John Downey](https://github.com/jtdowney))
110
111- The `gleam hex owner transfer` command now uses the flag `--user` instead of
112 the flag `--to`. The `gleam hex owner add` command now takes the package name
113 via the flag `--package`.
114 ([Louis Pilfold](https://github.com/lpil))
115
116- The error message when failing to decrypt the local Hex API key is now more
117 informative and helpful.
118 ([Moritz Böhme](https://github.com/MoritzBoehme))
119
120- The build tool can now authenticate requests to Hex with the API key from the
121 `HEXPM_READ_API_KEY` environment variable, when resolving and downloading
122 dependencies. This raises the request rate limit from the stricter per-IP
123 limit to the higher per-user limit, avoiding "rate limit exceeded" errors
124 when building large projects.
125 ([John Downey](https://github.com/jtdowney))
126
127### Language server
128
129- The language server now supports go-to-definition, find-references and rename
130 for record fields. These work on the field declaration, on labelled arguments,
131 on labelled patterns, on record updates and on `record.field` accesses, both
132 within a module and across modules. For example:
133
134 ```gleam
135 pub type Person {
136 Person(name: String, age: Int)
137 }
138
139 pub fn main() {
140 let lucy = Person(name: "Lucy", age: 10)
141 lucy.name
142 // ^ Go-to-definition jumps to the `name` field, and renaming it here
143 // renames the field everywhere it is used.
144 }
145 ```
146
147 ([Alistair Smith](https://github.com/alii))
148
149- The "pattern match on value" code action can now be used to pattern match on
150 values returned by function calls. For example:
151
152 ```gleam
153 pub fn main() {
154 load_user()
155 // ^^ Triggering the code action over here
156 }
157
158 fn load_user() -> Result(User, Nil) { todo }
159 ```
160
161 Will produce the following code:
162
163 ```gleam
164 pub fn main() {
165 case load_user() {
166 Ok(value) -> todo
167 Error(value) -> todo
168 }
169 }
170 ```
171
172 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
173
174- The language server now offers a code action to rewrite integers in a
175 different base. For example:
176
177 ```gleam
178 pub fn lucky_number() {
179 0b1011
180 //^^^^^^ Hovering this
181 }
182 ```
183
184 The language server is going to show code actions to rewrite it as `11`,
185 `0o13`, or `0xB`.
186 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
187
188- The "remove unreachable patterns" code action can now be triggered on
189 unreachable alternative patterns of a case expression.
190 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
191
192- The language server now permits renaming type variables in functions, types,
193 and constants. For example:
194
195 ```gleam
196 pub fn twice(value: a, f: fn(a) -> a) -> a {
197 // ^ Rename to "anything"
198 f(f(value))
199 }
200 ```
201
202 Produces:
203
204 ```gleam
205 pub fn twice(value: anything, f: fn(anything) -> anything) -> anything {
206 f(f(value))
207 }
208 ```
209
210 ([Surya Rose](https://github.com/GearsDatapacks))
211
212- The language server now automatically updates imports when a Gleam module is
213 renamed. For example:
214
215 ```gleam
216 import db_users
217
218 pub fn main() -> db_users.User {
219 db_users.new("username")
220 }
221 ```
222
223 Renaming `db_users.gleam` to `database/user.gleam` would produce:
224
225 ```gleam
226 import database/user
227
228 pub fn main() -> user.User {
229 user.new("username")
230 }
231 ```
232
233 ([Surya Rose](https://github.com/GearsDatapacks))
234
235- The language server now offers a code action to generate a missing type
236 definition when an unknown type is referenced. For example, if `Wibble`
237 is not defined:
238
239 ```gleam
240 pub fn run(data: Wibble(Int)) { todo }
241 ```
242
243 The code action will generate:
244
245 ```gleam
246 pub type Wibble(a)
247
248 pub fn run(data: Wibble(Int)) { todo }
249 ```
250
251 ([Daniele Scaratti](https://github.com/lupodevelop))
252
253- The language server now has "Discard unused variable" code action to discard
254 unused variables in different places. For example,
255
256 ```gleam
257 pub type Wibble {
258 Wibble(a: Int)
259 }
260
261 pub fn go(record: Wibble) -> Nil {
262 let wibble = 0
263 // ^ Trigger code action here
264
265 case record {
266 Wibble(a:) -> Nil
267 // ^ Trigger code action here
268 }
269
270 case [0, 1, 2] {
271 [_, ..] as wobble -> Nil
272 // ^ Trigger code action here
273 [] -> Nil
274 }
275
276 Nil
277 }
278 ```
279
280 Triggering the code action in all of these places would produce following code:
281
282 ```gleam
283 pub type Wibble {
284 Wibble(a: Int)
285 }
286
287 pub fn go(record: Wibble) -> Nil {
288 let _wibble = 0
289
290 case record {
291 Wibble(a: _) -> Nil
292 }
293
294 case [0, 1, 2] {
295 [_, ..] -> Nil
296 [] -> Nil
297 }
298
299 Nil
300 }
301 ```
302
303 ([Andrey Kozhev](https://github.com/ankddev))
304
305- The language server will now better rename types and values with import
306 aliases by removing `as ...` part in case new name is same as original name of
307 item. For example:
308
309 ```gleam
310 import wibble.{type Wibble as Wobble, Wibble as Wobble}
311
312 pub fn go() -> Wobble {
313 // ^^^^^^ Rename to `Wibble`
314 Wobble
315 //^^^^^^ Rename to `Wibble`
316 }
317 ```
318
319 Will now result in this code:
320
321 ```gleam
322 import wibble.{type Wibble, Wibble}
323
324 pub fn go() -> Wibble {
325 Wibble
326 }
327 ```
328
329 ([Andrey Kozhev](https://github.com/ankddev))
330
331- The language server now supports folding of comments and documentation
332 comments. For example, this code:
333
334 ```gleam
335 //// Very useful module.
336 ////
337 //// It could be used to make interesting things
338
339 /// Function to wibble.
340 ///
341 /// Not that it wobbles when wubble is true
342 pub fn wibble() {
343 // This todo here is temporary.
344 // It will need to be removed at some moment.
345 todo
346 }
347 ```
348
349 can now be folded to:
350
351 ```gleam
352 //// Very useful module. ...
353
354 /// Function to wibble. ...
355 pub fn wibble() {
356 // This todo here is temporary. ...
357 todo
358 }
359 ```
360
361 ([Andrey Kozhev](https://github.com/ankddev))
362
363- The "Convert to function call" code action will now convert the currently
364 hovered call and not only the final one.
365 ([Andrey Kozhev](https://github.com/ankddev))
366
367- When using the "Extract function" code action on statements whose values are
368 unused, the extracted function will return the last statement. For example:
369
370 ```gleam
371 fn main() {
372 //↓ start selection here
373 echo "line 2"
374 echo "line 3"
375 // ↑ end selection here
376 echo "line 4"
377 }
378 ```
379
380 will be turned into
381
382 ```gleam
383 fn main() {
384 function()
385 echo "line 4"
386 }
387
388 fn function() -> String {
389 echo "line 2"
390 echo "line 3"
391 }
392 ```
393
394 ([Gavin Morrow](https://github.com/gavinmorrow))
395
396- The language server now offers a code action to fix the new deprecated pipeline
397 syntax.
398 ([Surya Rose](https://github.com/GearsDatapacks))
399
400- The language server can now find references for and rename items when
401 triggered from an import statement:
402
403 ```gleam
404 import wibble.{type Wibble}
405 // ^^^^^^ Trigger find references or rename here
406
407 pub fn main() {
408 let _ = Wibble
409 }
410 ```
411
412 ([Gavin Morrow](https://github.com/gavinmorrow))
413
414- The language server now has "Convert to documentation comment" and
415 "Convert to regular comment" code actions. For example:
416
417 ```gleam
418 // Module description.
419 // Code action available here.
420
421 // Comment before function.
422 // Another code action here.
423 pub fn wibble() {
424 // No code action here.
425 todo
426 }
427
428 /// Doc comment.
429 /// Another code action here.
430 pub fn wobble () {
431 todo
432 }
433 ```
434
435 Triggering the code actions in all of these places will result in:
436
437 ```gleam
438 //// Module description.
439 //// Code action available here.
440
441 /// Comment before function.
442 /// Another code action here.
443 pub fn wibble() {
444 // No code action here.
445 todo
446 }
447
448 // Doc comment.
449 // Another code action here.
450 pub fn wobble () {
451 todo
452 }
453 ```
454
455 ([Daniel Venable](https://github.com/DanielVenable))
456
457- The "Generate Variant" code action now includes the name of the type to add
458 the variant to in its title.
459 ([0xda157](https://github.com/0xda157))
460
461### Formatter
462
463- Performance of the formatter has been improved.
464 `gleam format` has been measured to be up to 13% faster on projects like
465 `lustre`, with a 10% smaller peak memory footprint.
466 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
467
468- Formatter now removes import aliases if the aliased name is the
469 same as the original name. For example,
470
471 ```gleam
472 import wibble.{Wibble as Wibble}
473 ```
474
475 becomes
476
477 ```gleam
478 import wibble.{Wibble}
479 ```
480
481 ([Daniel Venable](https://github.com/DanielVenable))
482
483### Bug fixes
484
485- Fixed a bug where the generated Erlang `.app` file's `modules` list would only
486 contain the modules recompiled by the latest build, becoming empty on a warm
487 rebuild where nothing changed.
488 ([Charlie Tonneslan](https://github.com/c-tonneslan))
489
490- When using the language server to extract a function from within an anonymous
491 function, the return value of the extracted function is respected.
492
493 For example,
494
495 ```gleam
496 fn wibble() {
497 let wobble = fn() {
498 let random_number = 4
499 random_number * 42 // <- Extracting this line
500 }
501 }
502 ```
503
504 is turned into
505
506 ```gleam
507 fn wibble() {
508 let wobble = fn() {
509 let random_number = 4
510 function(random_number)
511 }
512 }
513 fn function(random_number: Int) -> Int {
514 random_number * 42
515 }
516 ```
517
518 ([Gavin Morrow](https://github.com/gavinmorrow))
519
520- Work around an ambiguity of the language server protocol that resulted in
521 editors like Zed inserting the wrong text when accepting type completions.
522 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
523
524- Fixed a bug where the post-publish message for pushing a git commit was
525 formatted incorrectly.
526 ([Louis Pilfold](https://github.com/lpil))
527
528- Fixed a bug where the compiler would generate invalid TypeScript type
529 definitions for records with a field named `constructor`.
530 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
531
532- Fixed a bug where the compiler would generate invalid code for `let assert`
533 expression with bit array patterns.
534 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
535
536- Fixed a bug where the compiler would evaluate the numerator and denominator
537 of a division in the wrong order.
538 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
539
540- Fixed a bug where the compiler would generate Erlang code that raises further
541 warnings for unused values.
542 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
543
544- Fixed a bug where the compiler would raise a warning for truncated int
545 segments when compiling a function with a JavaScript external.
546 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
547
548- Fixed a bug where the compiler would produce a confusing error message when
549 writing a constructor with a lowercase name.
550 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
551
552- Fixed a bug where guards with comments wouldn't be formatted properly.
553 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
554
555- A `gleam@@compile.erl` is no longer left in the build output of
556 `gleam compile-package`.
557 ([Louis Pilfold](https://github.com/lpil))
558
559- When using the language server to extract a function from within the body of a
560 use statement, only the selected statement(s) are extracted.
561
562 For example,
563
564 ```gleam
565 pub fn wibble() {
566 use wobble <- result.map(todo)
567 echo wobble as "1" // <- Extracting this line
568 echo wobble as "2"
569 }
570 ```
571
572 is turned into
573
574 ```gleam
575 pub fn wibble() {
576 use wobble <- result.map(todo)
577 function(wobble)
578 echo wobble as "2"
579 }
580 fn function(wobble: a) -> a {
581 echo wobble as "1"
582 }
583 ```
584
585 ([Gavin Morrow](https://github.com/gavinmorrow))
586
587- Fixed a bug where the JavaScript code generator could produce duplicate `let`
588 declarations when a variable was reassigned after being shadowed inside a
589 directly matching `case` branch.
590 ([Eyup Can Akman](https://github.com/eyupcanakman))
591
592- Fixed a bug where the language server would produce wrong code when triggering
593 rename of types and values with import aliases.
594 ([Andrey Kozhev](https://github.com/ankddev))
595
596- Fixed a bug where referencing qualified constructors in constant where a value
597 of the same name exists in scope would cause invalid code to be generated.
598 ([Surya Rose](https://github.com/GearsDatapacks))
599
600- Fixed a bug that would result in `gleam build` being slower than necessary
601 when finding the Gleam files of a package.
602 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
603
604- Fixed a bug where the compiler would not be able to correctly parse negative
605 numbers written in binary, octal, or hexadecimal base.
606 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
607
608- The formatter now properly formats binary operations in bit array size
609 segments.
610 ([Andrey Kozhev](https://github.com/ankddev))
611
612- Fixed a bug where after removing dependencies with `gleam remove` if a
613 removed dependency is still used the build would succeed, resulting in
614 runtime crash due to missing files.
615 ([Andrey Kozhev](https://github.com/ankddev))
616
617- The build tool will no longer panic when unable to lock the build directory.
618 ([Louis Pilfold](https://github.com/lpil))
619
620- The formatter now properly indents multiline trailing comments inside of
621 multiline lists and tuples.
622 ([0xda157](https://github.com/0xda157))
623
624- Fixed a bug where the compiler would panic on the first HTTPS request on
625 Android.
626 ([John Downey](https://github.com/jtdowney))
627
628- Fixed a bug where the language server would not show autocomplete for record
629 fields of internal types within the same package.
630 ([Surya Rose](https://github.com/GearsDatapacks))
631
632- Fixed a bug where warnings and errors in the arguments of a call to a
633 function literal would be reported multiple times.
634 ([John Downey](https://github.com/jtdowney))
635
636- Fixed a bug where pattern matching on overlapping string prefixes with guards
637 could generate incorrect JavaScript.
638 ([John Downey](https://github.com/jtdowney))
639
640- Fixed a bug where running `gleam docs build` on non-Erlang target projects
641 with a warm cache would not produce the module pages.
642 ([Matt Champagne](https://github.com/han-tyumi))
643
644- Fixed a bug where an incorrect `package-interface.json` would be generated for
645 certain type aliases.
646 ([Surya Rose](https://github.com/GearsDatapacks))
647
648- Fixed a bug where the compiler would report a module import as unused when
649 its local name matched another imported module's full name.
650 ([John Downey](https://github.com/jtdowney))