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.6.0 - 2024-11-18
9
10### Bug fixes
11
12- Fixed a bug where the language server would delete pieces of code when
13 applying a suggested autocompletion.
14 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
15
16## v1.6.0-rc2 - 2024-11-14
17
18### Build tool
19
20- The version of Erlang used in the GitHub Actions workflow created by
21 `gleam new` has been increased from v26.0.2 to v27.1.2.
22 ([Richard Viney](https://github.com/richard-viney))
23
24### Bug fixes
25
26- Fixed a bug where some reserved field names were not properly escaped in
27 custom types on the JavaScript target.
28 ([yoshi](https://github.com/joshi-monster))
29
30- Fixed a bug where a warning about unsafe integers on the JavaScript target was
31 emitted when the enclosing function has an external JavaScript implementation.
32 ([Richard Viney](https://github.com/richard-viney))
33
34- Fixed a bug where updating a dependency could break the build cache.
35 ([yoshi](https://github.com/joshi-monster))
36
37- Fixed a bug where if the build directory was not writable then the build tool
38 would crash when trying to lock the build directory.
39 ([Zak Farmer](https://github.com/ZakFarmer))
40
41## v1.6.0-rc1 - 2024-11-10
42
43### Build tool
44
45- The `--template` flag for `gleam new` takes the values `erlang` and
46 `javascript` to specify what target to use, with `erlang` being the default.
47 ([Mohammed Khouni](https://github.com/Tar-Tarus))
48
49- The Erlang/Elixir compiler process is now reused for all packages, shaving
50 off 0.3-0.5s per compiled package.
51 ([yoshi](https://github.com/joshi-monster))
52
53- When a symlink cannot be made on Windows due to lack of permissions the error
54 now includes information on how to enable Windows' developer mode, enabling
55 symlinks.
56 ([Louis Pilfold](https://github.com/lpil))
57
58- The cli can now update individual dependencies.
59
60 `gleam update` and `gleam deps update` now take an optional list of package
61 names to update:
62
63 ```sh
64 gleam update package_a
65 gleam deps update package_b package_c
66 ```
67
68 This allows for selective updating of dependencies. When package names are
69 provided, only those packages and their unique dependencies are unlocked and
70 updated. If no package names are specified, the command behaves as before,
71 updating all dependencies.
72
73 ([Jason Sipula](https://github.com/SnakeDoc))
74
75- The `repository` config in `gleam.toml` can now optionally include a `path`
76 so that source links in generated documentation are correct for packages that
77 aren't located at the root of their repository:
78
79 ```toml
80 [repository]
81 type = "github"
82 user = "gleam-lang"
83 repo = "gleam"
84 path = "packages/my_package"
85 ```
86
87 ([Richard Viney](https://github.com/richard-viney))
88
89### Compiler
90
91- The compiler now prints correctly qualified or aliased type names when
92 printing type errors.
93
94 This code:
95
96 ```gleam
97 pub type Int
98
99 pub fn different_int_types(value: Int) {
100 value
101 }
102
103 pub fn main() {
104 different_int_types(20)
105 }
106 ```
107
108 Produces this error:
109
110 ```
111 error: Type mismatch
112 ┌─ /src/wibble.gleam:8:23
113 │
114 8 │ different_int_types(20)
115 │ ^^
116
117 Expected type:
118
119 Int
120
121 Found type:
122
123 gleam.Int
124 ```
125
126 ([Surya Rose](https://github.com/GearsDatapacks))
127
128- The compiler can now suggest to pattern match on a `Result(a, b)` if it's
129 being used where a value of type `a` is expected. For example, this code:
130
131 ```gleam
132 import gleam/list
133 import gleam/int
134
135 pub fn main() {
136 let not_a_number = list.first([1, 2, 3])
137 int.add(1, not_a_number)
138 }
139 ```
140
141 Results in the following error:
142
143 ```txt
144 error: Type mismatch
145 ┌─ /src/one/two.gleam:6:9
146 │
147 6 │ int.add(1, not_a_number)
148 │ ^^^^^^^^^^^^
149
150 Expected type:
151
152 Int
153
154 Found type:
155
156 Result(Int, a)
157
158 Hint: If you want to get a `Int` out of a `Result(Int, a)` you can pattern
159 match on it:
160
161 case result {
162 Ok(value) -> todo
163 Error(error) -> todo
164 }
165 ```
166
167 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
168
169- Improved the error message for unknown record fields, displaying an additional
170 note on how to have a field accessor only if it makes sense.
171 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
172
173- The compiler now ignores `optional` dependencies when resolving versions
174 unless explicitly specified.
175 ([Gustavo Inacio](https://github.com/gusinacio))
176
177- Improved the error message for using `@deprecated` with no deprecation message
178 ([Jiangda Wang](https://github.com/frank-iii))
179
180- Optimised creation of bit arrays on the JavaScript target.
181 ([Richard Viney](https://github.com/richard-viney))
182
183- The compiler can now infer the variant of custom types within expressions that
184 construct or pattern match on them.
185
186 Using this information it can now be more precise with exhaustiveness
187 checking, identifying patterns for the other variants as unnecessary.
188
189 ```gleam
190 pub type Pet {
191 Dog(name: String, cuteness: Int)
192 Turtle(name: String, speed: Int, times_renamed: Int)
193 }
194
195 pub fn main() {
196 // We know `charlie` is a `Dog`...
197 let charlie = Dog("Charles", 1000)
198
199 // ...so you do not need to match on the `Turtle` variant
200 case charlie {
201 Dog(..) -> todo
202 }
203 }
204 ```
205
206 This also means that the record update syntax can be used on multi-variant
207 custom types, so long as the variant can be inferred from the surrounding
208 code.
209
210 ```gleam
211 pub fn rename(pet: Pet, to name: String) -> Pet {
212 case pet {
213 Dog(..) -> Dog(..pet, name:)
214 Turtle(..) -> Turtle(..pet, name:, times_renamed: pet.times_renamed + 1)
215 }
216 }
217 ```
218
219 Variant specific fields can also be used with the accessor syntax.
220
221 ```gleam
222 pub fn speed(pet: Pet) -> Int {
223 case pet {
224 Dog(..) -> 500
225 Turtle(..) -> pet.speed
226 }
227 }
228 ```
229
230 ([Surya Rose](https://github.com/GearsDatapacks))
231
232- When targeting JavaScript the compiler now emits a warning for integer
233 literals and constants that lie outside JavaScript's safe integer range:
234
235 ```txt
236 warning: Int is outside the safe range on JavaScript
237 ┌─ /Users/richard/Desktop/int_test/src/int_test.gleam:1:15
238 │
239 1 │ pub const i = 9_007_199_254_740_992
240 │ ^^^^^^^^^^^^^^^^^^^^^ This is not a safe integer on JavaScript
241
242 This integer value is too large to be represented accurately by
243 JavaScript's number type. To avoid this warning integer values must be in
244 the range -(2^53 - 1) - (2^53 - 1).
245
246 See JavaScript's Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
247 properties for more information.
248 ```
249
250 ([Richard Viney](https://github.com/richard-viney))
251
252### Formatter
253
254- The formatter no longer removes the first argument from a function
255 which is part of a pipeline if the first argument is a capture
256 and it has a label. This snippet of code is left as is by the formatter:
257
258 ```gleam
259 pub fn divide(dividend a: Int, divisor b: Int) -> Int {
260 a / b
261 }
262
263 pub fn main() {
264 10 |> divide(dividend: _, divisor: 2)
265 }
266 ```
267
268 Whereas previously, the label of the capture variable would be lost:
269
270 ```gleam
271 pub fn divide(dividend a: Int, divisor b: Int) -> Int {
272 a / b
273 }
274
275 pub fn main() {
276 10 |> divide(divisor: 2)
277 }
278 ```
279
280 ([Surya Rose](https://github.com/GearsDatapacks))
281
282### Language Server
283
284- The Language Server now displays correctly qualified or aliased type names
285 when hovering over a value in a Gleam file:
286
287 ```gleam
288 import gleam/option
289
290 const value = option.Some(1)
291 // ^ hovering here shows `option.Option(Int)`
292 ```
293
294 ```gleam
295 import gleam/option.{type Option as Maybe}
296
297 const value = option.Some(1)
298 // ^ hovering here shows `Maybe(Int)`
299 ```
300
301 ([Surya Rose](https://github.com/GearsDatapacks))
302
303- The Language Server now suggests a code action to add type annotations to
304 local variables, constants and functions:
305
306 ```gleam
307 pub fn add_int_to_float(a, b) {
308 a +. int.to_float(b)
309 }
310 ```
311
312 Becomes:
313
314 ```gleam
315 pub fn add_int_to_float(a: Float, b: Int) -> Float {
316 a +. int.to_float(b)
317 }
318 ```
319
320 ([Surya Rose](https://github.com/GearsDatapacks))
321
322- The Language Server now suggests a code action to convert qualified imports to
323 unqualified imports, which updates all occurrences of the qualified name
324 throughout the module:
325
326 ```gleam
327 import option
328
329 pub fn main() {
330 option.Some(1)
331 }
332 ```
333
334 Becomes:
335
336 ```gleam
337 import option.{Some}
338
339 pub fn main() {
340 Some(1)
341 }
342 ```
343
344 ([Jiangda Wang](https://github.com/Frank-III))
345
346- The Language Server now suggests a code action to convert unqualified imports
347 to qualified imports, which updates all occurrences of the unqualified name
348 throughout the module:
349
350 ```gleam
351 import list.{map}
352
353 pub fn main() {
354 map([1, 2, 3], fn(x) { x * 2 })
355 }
356 ```
357
358 Becomes:
359
360 ```gleam
361 import list.{}
362
363 pub fn main() {
364 list.map([1, 2, 3], fn(x) { x * 2 })
365 }
366 ```
367
368 ([Jiangda Wang](https://github.com/Frank-III))
369
370### Bug Fixes
371
372- Fixed a bug in the compiler where shadowing a sized value in a bit pattern
373 would cause invalid erlang code to be generated.
374 ([Antonio Iaccarino](https://github.com/eingin))
375
376- Fixed a bug where the formatter would not format strings with big grapheme
377 clusters properly.
378 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
379
380- Fixed the `BitArray` constructor not being present in the types for the
381 JavaScript prelude.
382 ([Richard Viney](https://github.com/richard-viney))
383
384- Fixed a bug where generated TypeScript definitions were invalid for opaque
385 types that use a private type.
386 ([Richard Viney](https://github.com/richard-viney))
387
388- Fixed the prelude re-export in generated TypeScript definitions.
389 ([Richard Viney](https://github.com/richard-viney))
390
391- Fixed a bug where the compiler would incorrectly type-check and compile
392 calls to functions with labelled arguments in certain cases.
393 ([Surya Rose](https://github.com/GearsDatapacks))
394
395- Fixed a bug where importing type aliases that reference unimported modules
396 would generate invalid TypeScript definitions.
397 ([Richard Viney](https://github.com/richard-viney))
398
399- When splitting a constant list made of records, the formatter will keep each
400 item on its own line to make things easier to read.
401 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
402
403- Fixed a bug where the compiler would crash when pattern matching on a type
404 which was defined with duplicate fields in one of its variants.
405 ([Surya Rose](https://github.com/GearsDatapacks))
406
407- Fixed a bug where the WASM compiler would return incomplete JavaScript when
408 unsupported features were used. It now returns a compilation error.
409 ([Richard Viney](https://github.com/richard-viney))
410
411- Fixed a bug where incorrect code would be generated for external function on
412 the Erlang target if any of their arguments were discarded.
413 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
414
415- Fixed a bug in the error message when using wrong values in a pipe where the
416 message would swap the "Expected" and "Found" types.
417 ([Markus Pettersson](https://github.com/MarkusPettersson98/))
418
419- Fixed a bug where the parser would incorrectly parse a record constructor with
420 no arguments.
421 ([Louis Pilfold](https://github.com/lpil))
422
423- Fixed a bug where the parser would incorrectly parse a generic type
424 constructor with no arguments.
425 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
426
427- Fixed a bug where the parser would incorrectly parse a generic type definition
428 with no arguments.
429 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
430
431- Fixed a bug where the language server wouldn't show hints when hovering over
432 the tail of a list.
433 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
434
435- Fixed a bug where attempting to jump to the definition of a type from the
436 annotation of a parameter of an anonymous function would do nothing.
437 ([Surya Rose](https://github.com/GearsDatapacks))
438
439- Fixed a bug where referencing record constructors in JavaScript guards but
440 not calling them could produce invalid code.
441 ([PgBiel](https://github.com/PgBiel))
442
443- Fixed a bug where using the label shorthand syntax inside of a record update
444 wouldn't emit a warning when the minimum specified Gleam version was < 1.4.0.
445 ([yoshi](https://github.com/joshi-monster))
446
447- Fixed a bug where no error would be reported when duplicate labelled
448 arguments were supplied in a record update.
449 ([Surya Rose](https://github.com/GearsDatapacks))
450
451- Fixed a bug where an incorrect bit array would be generated on JavaScript for
452 negative `Int` values when the segment's `size` was wider than 48 bits or when
453 the `Int` value was less than the minimum representable value for the segment
454 size.
455 ([Richard Viney](https://github.com/richard-viney))
456
457- Fixed a bug where an incorrect `Int` would be returned when pattern matching
458 to a negative value wider than 48 bits in a bit array.
459 ([Richard Viney](https://github.com/richard-viney))
460
461- Fixed a bug where unused values coming from other modules wouldn't raise a
462 warning.
463 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
464
465## v1.5.1 - 2024-09-26
466
467### Bug Fixes
468
469- Fixed a bug where Erlang file paths would not be escaped on Windows.
470 ([Louis Pilfold](https://github.com/lpil))