Fork of daniellemaywood.uk/gleam — Wasm codegen work
1<!--
2 SPDX-License-Identifier: Apache-2.0
3 SPDX-FileCopyrightText: 2020 The Gleam contributors
4-->
5
6# Changelog
7
8## v1.2.0 - 2024-05-27
9
10## v1.2.0-rc2 - 2024-05-27
11
12### Bug fixes
13
14- Fixed a bug where the formatter would incorrectly move comments at the start
15 of an anonymous function to the end of the arguments.
16 ([Ameen Radwan](https://github.com/Acepie))
17
18- Fixed a bug where the formatter would not indent a multiline function used
19 in a pipeline.
20 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
21
22- Fixed a bug where the compiler would raise a warning for matching on a literal
23 value if the case expression is used just for its guards.
24 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
25
26- Fixed a bug where not all the analysis errors would be presented to the
27 programmer. ([Louis Pilfold](https://github.com/lpil))
28
29## v1.2.0-rc1 - 2024-05-23
30
31### Build tool
32
33- A helpful error message is now shown if the `manifest.toml` file has been
34 edited to be invalid in some way.
35
36 ```
37 error: Corrupt manifest.toml
38
39 The `manifest.toml` file is corrupt.
40
41 Hint: Please run `gleam update` to fix it.
42 ```
43
44 ([zahash](https://github.com/zahash))
45
46- The error message shown when unable to find package versions that satisfy all
47 the version constraints specified for a project's dependencies has been
48 greatly improved.
49
50 ```
51 error: Dependency resolution failed
52
53 An error occurred while determining what dependency packages and
54 versions should be downloaded.
55 The error from the version resolver library was:
56
57 Unable to find compatible versions for the version constraints in your
58 gleam.toml. The conflicting packages are:
59
60 - hellogleam
61 - lustre_dev_tools
62 - glint
63 ```
64
65 ([zahash](https://github.com/zahash))
66
67- A link to the package on Hex is no longer auto-added to the HTML documentation
68 when building them locally. It is still added when publishing to Hex.
69 ([Pi-Cla](https://github.com/Pi-Cla))
70
71- An error is now emitted when compiling to Erlang and there is a Gleam module
72 that would overwrite a built-in Erlang/OTP module, causing cryptic errors and
73 crashes.
74 ([Louis Pilfold](https://github.com/lpil))
75
76 ```
77 error: Erlang module name collision
78
79 The module `src/code.gleam` compiles to an Erlang module named `code`.
80
81 By default Erlang includes a module with the same name so if we were to
82 compile and load your module it would overwrite the Erlang one, potentially
83 causing confusing errors and crashes.
84
85 Hint: Rename this module and try again.
86 ```
87
88- New subcommand `gleam hex revert` added.
89
90 - You can specify the options like this:
91 `gleam hex revert --package gling --version 1.2.3`
92 - A new package can be reverted or updated within 24 hours of it's initial
93 publish, a new version of an existing package can be reverted or updated
94 within one hour.
95 - You could already update packages even before this release by running:
96 `gleam publish` again.
97
98 ([Pi-Cla](https://github.com/Pi-Cla))
99
100- When the user tries to replace a release without the `--replace` flag
101 the error message now mentions the lack of a `--replace` flag.
102
103 ```
104 error: Version already published
105
106 Version v1.0.0 has already been published.
107 This release has been recently published so you can replace it
108 or you can publish it using a different version number
109
110 Hint: Please add the --replace flag if you want to replace the release.
111 ```
112
113 ([Pi-Cla](https://github.com/Pi-Cla))
114
115### Compiler
116
117- The compiler will now raise a warning for `let assert` assignments where the
118 assertion is redundant.
119
120 ```
121 warning: Redundant assertion
122 ┌─ /home/lucy/src/app/src/app.gleam:4:7
123 │
124 4 │ let assert x = get_name()
125 │ ^^^^^^ You can remove this
126
127 This assertion is redundant since the pattern covers all possibilities.
128 ```
129
130 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
131
132- Empty case expressions are no longer parse errors and will instead be
133 exhaustiveness errors.
134 ([Race Williams](https://github.com/raquentin))
135
136- Improve error message if importing type using the value import syntax or vice
137 versa.
138
139 ```
140 error: Unknown module field
141 ┌─ /src/one/two.gleam:1:19
142 │
143 1 │ import gleam/one.{One}
144 │ ^^^ Did you mean `type One`?
145
146 `One` is only a type, it cannot be imported as a value.
147 ```
148
149 ```
150 error: Unknown module type
151 ┌─ /src/one/two.gleam:1:19
152 │
153 1 │ import gleam/two.{type Two}
154 │ ^^^^^^^^ Did you mean `Two`?
155
156 `Two` is only a value, it cannot be imported as a type.
157 ```
158
159 ([Pi-Cla](https://github.com/Pi-Cla/))
160
161- The compiler will now raise a warning when you try to use `todo` or `panic` as
162 if they were functions: this could previously lead to a confusing behaviour
163 since one might expect the arguments to be printed in the error message.
164 The error message now suggests the correct way to add an error message to
165 `todo` and `panic`.
166
167 ```
168 warning: Todo used as a function
169 ┌─ /src/warning/wrn.gleam:2:16
170 │
171 2 │ todo(1)
172 │ ^
173
174 `todo` is not a function and will crash before it can do anything with
175 this argument.
176
177 Hint: if you want to display an error message you should write
178 `todo as "my error message"`
179 See: https://tour.gleam.run/advanced-features/todo/
180 ```
181
182 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
183
184- Improve error message when something that is not a function appears on the
185 right hand side of `<-` in a `use` expression.
186
187 ```txt
188 error: Type mismatch
189 ┌─ /src/one/two.gleam:2:8
190 │
191 2 │ use <- 123
192 │ ^^^
193
194 In a use expression, there should be a function on the right hand side of
195 `<-`, but this value has type:
196
197 Int
198
199 See: https://tour.gleam.run/advanced-features/use/
200 ```
201
202 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
203
204- Improve error message when a function with the wrong number of arguments
205 appears on the right hand side of `<-` in a `use` expression.
206
207 ```txt
208 error: Incorrect arity
209 ┌─ /src/one/two.gleam:3:8
210 │
211 3 │ use <- func
212 │ ^^^^ Expected no arguments, got 1
213
214 The function on the right of `<-` here takes no arguments.
215 But it has to take at least one argument, a callback function.
216
217 See: https://tour.gleam.run/advanced-features/use/
218 ```
219
220 ```txt
221 error: Incorrect arity
222 ┌─ /src/one/two.gleam:3:8
223 │
224 3 │ use <- f(1, 2)
225 │ ^^^^^^^ Expected 2 arguments, got 3
226
227 The function on the right of `<-` here takes 2 arguments.
228 All the arguments have already been supplied, so it cannot take the
229 `use` callback function as a final argument.
230
231 See: https://tour.gleam.run/advanced-features/use/
232 ```
233
234 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
235
236- Improve error message when the callback function of a `use` expression returns
237 a value with the wrong type.
238 Now the error will point precisely to the last statement and not complain
239 about the whole block saying it has the wrong function type.
240 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
241
242- The compiler will now raise a warning when pattern matching on a literal value
243 like a list, a tuple, integers, strings, etc.
244
245 ```
246 warning: Redundant list
247 ┌─ /src/warning/wrn.gleam:2:14
248 │
249 2 │ case [1, 2] {
250 │ ^^^^^^ You can remove this list wrapper
251
252 Instead of building a list and matching on it, you can match on its
253 contents directly.
254 A case expression can take multiple subjects separated by commas like this:
255
256 case one_subject, another_subject {
257 _, _ -> todo
258 }
259
260 See: https://tour.gleam.run/flow-control/multiple-subjects/
261 ```
262
263 ```
264 warning: Match on a literal value
265 ┌─ /src/warning/wrn.gleam:4:8
266 │
267 4 │ case 1 {
268 │ ^ There's no need to pattern match on this value
269
270 Matching on a literal value is redundant since you can already tell which
271 branch is going to match with this value.
272
273 ```
274
275 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
276
277- The compiler will now continue module analysis when there are errors in top
278 level definitions. This means that when these errors occur the compiler will
279 continue analysing the rest of the code to find other errors and type
280 information.
281
282 When using the build tool this means that the programmer will be shown
283 multiple error messages when there are multiple problems in a module.
284
285 When using the language server multiple error diagnostics will be shown, and
286 the compiler will get updated type information about the code even when there
287 are errors. This should improve the accuracy of feedback and suggestions from
288 the language server as its information about the code will be more up-to-date.
289 ([Ameen Radwan](https://github.com/Acepie)) and
290 ([Louis Pilfold](https://github.com/Acepie))
291
292- An informative error message is now emitted when attempting to use a function
293 from another module in a constant expression. Previously this would result in
294 a cryptic parse error.
295
296 ```
297 error: Syntax error
298 ┌─ /src/parse/error.gleam:3:18
299 │
300 3 │ const wib: Int = wibble(1, "wobble")
301 │ ^^^^^^^ Functions can only be called within other functions
302 ```
303
304 ([Nino Annighoefer](https://github.com/nino))
305
306- The compiler will now provide more helpful error messages when triple equals
307 are used instead of double equals.
308
309 ```
310 error: Syntax error
311 ┌─ /src/parse/error.gleam:4:37
312 │
313 4 │ [1,2,3] |> list.filter(fn (a) { a === 3 })
314 │ ^^^ Did you mean `==`?
315
316 Gleam uses `==` to check for equality between two values.
317 See: https://tour.gleam.run/basics/equality
318 ```
319
320 ([Rabin Gaire](https://github.com/rabingaire))
321
322- The compiler will now raise a warning for unreachable code that comes after
323 a panicking expression.
324
325 ```
326 pub fn main() {
327 panic
328 "unreachable!"
329 }
330 ```
331
332 ```
333 warning: Unreachable code
334 ┌─ /src/warning/wrn.gleam:3:11
335 │
336 3 │ "unreachable!"
337 │ ^^^^^^^^^^^^^^
338
339 This code is unreachable because it comes after a `panic`.
340 ```
341
342 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
343
344- JavaScript external module names may now include the character `@`.
345 ([Louis Pilfold](https://github.com/lpil))
346
347### Formatter
348
349- Redundant alias names for imported modules are now removed.
350
351 ```gleam
352 import gleam/result as result
353 ```
354
355 is formatted to
356
357 ```gleam
358 import gleam/result
359 ```
360
361 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
362
363- Comments are no longer moved out of constant lists, constant tuples and empty
364 tuples. You can now write this:
365
366 ```gleam
367 const values = [
368 // This is a comment!
369 1, 2, 3
370 // Another comment...
371 11,
372 // And a final one.
373 ]
374 ```
375
376 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
377
378- Comments at the end of an anonymous function are no longer moved out of it.
379 You can now write this:
380
381 ```gleam
382 fn() {
383 todo
384 // A comment here!
385 }
386 ```
387
388 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
389
390- Pipes can now be placed on a single line if they are short enough:
391
392 ```gleam
393 [1, 2, 3] |> list.map(int.to_string) |> string.join(with: "\n")
394 ```
395
396 In addition you can also force the formatter to break a pipe on multiple lines
397 by manually breaking it. This:
398
399 ```gleam
400 [1, 2, 3]
401 // By putting a newline here I'm telling the formatter to split the pipeline
402 |> list.map(int.to_string) |> string.join(with: "\n")
403 ```
404
405 Will turn into this:
406
407 ```gleam
408 [1, 2, 3]
409 |> list.map(int.to_string)
410 |> string.join(with: "\n")
411 ```
412
413 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
414
415- Comments appearing after arguments are no longer moved to a different place.
416 You can now write all of those:
417
418 ```gleam
419 type Record {
420 Record(
421 field: String,
422 // comment_line_1: String,
423 // comment_line_2: String,
424 )
425 }
426 ```
427
428 ```gleam
429 pub fn main() {
430 fn(
431 a,
432 // A comment 2
433 ) {
434 1
435 }
436 }
437 ```
438
439 ```gleam
440 fn main() {
441 let triple = Triple(1, 2, 3)
442 let Triple(
443 a,
444 ..,
445 // comment
446 ) = triple
447 a
448 }
449 ```
450
451 ```gleam
452 type Record {
453 Record(
454 // comment_line_1: String,
455 // comment_line_2: String,
456 )
457 }
458 ```
459
460 ([Mateusz Ledwoń](https://github.com/Axot017))
461
462### Language Server
463
464- The code action to remove unused imports now removes the entire line is
465 removed if it would otherwise be left blank.
466 ([Milco Kats](https://github.com/katsmil))
467
468- Hover for type annotations is now separate from the thing being annotated.
469 ([Ameen Radwan](https://github.com/Acepie))
470
471- Go to definition now works for direct type annotations.
472 ([Ameen Radwan](https://github.com/Acepie))
473
474- Go to definition now works for import statements.
475 ([Ameen Radwan](https://github.com/Acepie))
476
477- Hover now works for unqualified imports.
478 ([Ameen Radwan](https://github.com/Acepie))
479
480- The language server now detects when the `gleam.toml` config file has changed
481 even if the client does not support watching files. This means that changes to
482 the default target, new dependencies, and other configuration will be
483 automatically detected.
484 ([Louis Pilfold](https://github.com/lpil))
485
486- Completions are now provided for values and types for use in unqualified
487 imports.
488 ([Ameen Radwan](https://github.com/Acepie))
489
490- The character `.` is now advertised as a completion trigger character.
491 ([Louis Pilfold](https://github.com/lpil))
492
493- A new code action has been added to remove redundant tuples around case
494 expression subjects and patterns when possible.
495 ([Nicky Lim](https://github.com/nicklimmm))
496
497 ```
498 case #(x, y) {
499 #(1, 2) -> 0
500 #(_, _) -> 1
501 }
502 ```
503
504 Is rewritten to:
505
506 ```
507 case x, y {
508 1, 2 -> 0
509 _, _ -> 1
510 }
511 ```
512
513- The language server will now register information about code even when there
514 was a type error or similar. This means that the language server will be able
515 to produce some up-to-date information about the project, even when errors are
516 present. This should greatly improve the experience using the language server.
517 ([Louis Pilfold](https://github.com/lpil))
518
519### Bug Fixes
520
521- Fixed [RUSTSEC-2021-0145](https://rustsec.org/advisories/RUSTSEC-2021-0145) by
522 using Rust's `std::io::IsTerminal` instead of the `atty` library.
523 ([Pi-Cla](https://github.com/Pi-Cla))
524
525- Fixed the generated `mod` property in the Erlang application file when using
526 the `application_start_module` property in `gleam.toml`.
527 ([Alex Manning](https://github.com/rawhat))
528
529- Fixed a confusing error message when using some reserved keywords.
530 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
531
532- Fixed variables in constant expressions not being escaped correctly when
533 exporting to JavaScript.
534 ([PgBiel](https://github.com/PgBiel))
535
536- Fixed a typo when attempting to publish a package with non-Hex dependencies
537 ([inoas](https://github.com/inoas))
538
539- Fixed import completions not appearing in some editors due to the range being
540 longer than the line.
541 ([Ameen Radwan](https://github.com/Acepie))
542
543- Fixed a bug where TypeScript definitions files would use `null` instead of
544 `undefined`.
545 ([Louis Pilfold](https://github.com/lpil))
546
547- Fixed a bug where unreachable infinite cases would not be detected when
548 after a discard or variable pattern.
549 ([Ameen Radwan](https://github.com/Acepie)) and
550 ([Pi-Cla](https://github.com/Pi-Cla))
551
552- Fixed a bug where module imports in guard clauses would not be generated
553 correctly for js target.
554 ([Ameen Radwan](https://github.com/Acepie))
555
556- Fixed a bug where formatting constant lists of tuples would force the
557 tuples to be broken across multiple lines, even when they could fit on a
558 single line.
559 ([Isaac Harris-Holt](https://github.com/isaacharrisholt))
560
561- Fixed a bug where floating points in scientific notation with no trailing
562 zeros would generate invalid Erlang code.
563 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
564
565- Fixed a bug where having utf8 symbols in `gleam.toml`'s description value
566 would result in an HTTP 500 error when running `gleam publish`.
567 ([inoas](https://github.com/inoas))
568
569- Unicode `\u{}` syntax in bit_array string segments now produce valid Erlang
570 unicode characters ([Pi-Cla](https://github.com/Pi-Cla))
571
572- Fixed a bug where using a constant defined in another module that referenced
573 a private function could generate invalid code on the Erlang target.
574 ([Shayan Javani](https://github.com/massivefermion))
575
576- Fixed a bug where the language server would dynamically request the client to
577 watch files even when the client has stated it does not support that.
578 ([Louis Pilfold](https://github.com/lpil))
579
580- Fixed a bug where local path dependencies could be mishandled on Windows.
581 ([Francisco Montanez](https://github.com/Francisco-Montanez))
582
583- Fixed a bug where adding a comment to a case clause would cause it to break
584 on multiple lines.
585 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
586
587- Fixed a bug where pattern matching on a string prefix containing an escape
588 code could generate incorrect Erlang code.
589 ([Nashwan Azhari](https://github.com/aznashwan))
590
591- Fixed a bug where the formatter would produce uneven indentation within
592 multi-line comments at the bottom of case blocks.
593 ([Race Williams](https://github.com/raquentin))