# Changelog

## Unreleased

### Compiler

- On the JavaScript target, bit arrays can now use the `unit` option to control
  the units of the `size` option.
  ([Surya Rose](https://github.com/GearsDatapacks))

- The compiler can now tell if string branches are unreachable. For example, the
  following code:

  ```gleam
  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.
  ```

  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- On the JavaScript target, blocks and various other expressions no longer
  compile to immediately invoked function expressions.
  ([Surya Rose](https://github.com/GearsDatapacks))

- On the JavaScript target, bit arrays can now use 16-bit floats in expressions
  and patterns.
  ([Richard Viney](https://github.com/richard-viney))

- Improve the error messages for unknown and missing target names
  in target attributes.
  ([Alexander Keleschovsky](https://github.com/AlecGhost))

- Fixed a bug where a temporarily moved or removed file does not get recompiled,
  even though its dependencies changed in the meanwhile.
  ([Sakari Bergen](http://github.com/sbergen))

- 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:

  ```gleam
  // warning: unused
  fn some_recursive_function() {
    some_recursive_function()
  }
  ```

  ([Surya Rose](https://github.com/GearsDatapacks))

- The compiler now emits a warning when using `let assert` to assert a value
  whose variant has already been inferred. For example:

  ```gleam
  // warning: This will always crash
  let assert Ok(_) = Error("Some error")
  ```

  ([Surya Rose](https://github.com/GearsDatapacks))

- It is now possible to omit the `:float` option for literal floats used in a
  `BitArray` segment.

  ```gleam
  <<1.11>>
  ```

  Is the same as:

  ```gleam
  <<1.11:float>>
  ```

  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

### Build tool

- Include a type annotation for the `main` function generated by `gleam new`.
  ([Drew Olson](https://github.com/drewolson))

- Two entry point scripts are now always generated by `gleam export erlang-shipment`:

  - `entrypoint.sh` for POSIX Shell
  - `entrypoint.ps1` for PowerShell
    ([Greg Burri](https://github.com/ummon))

- `gleam export` now takes a `package-information` option to export the
  project's `gleam.toml` as a JSON file.
  ([Rodrigo Álvarez](https://github.com/Papipo))

- Improve error messages when encrypting and decrypting local Hex API key.
  ([Samuel Cristobal](https://github.com/scristobal))

### Language server

- The language server now allows renaming of functions, constants,
  custom type variants and custom types across modules. For example:

  ```gleam
  // wibble.gleam
  pub fn wibble() {
    wibble()
  //^ Trigger rename
  }
  // wobble.gleam
  import wibble

  pub fn main() {
    wibble.wibble()
  }
  ```

  Becomes:

  ```gleam
  // wibble.gleam
  pub fn wobble() {
    wobble()
  }
  // wobble.gleam
  import wibble

  pub fn main() {
    wibble.wobble()
  }
  ```

  ([Surya Rose](https://github.com/GearsDatapacks))

- 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:

  ```gleam
  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:

  ```gleam
  pub type Pokemon {
    Pokemon(id: Int, name: String, moves: List(String))
  }

  pub fn main() {
    let Pokemon(id:, name:, moves:) = todo
  }
  ```

  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- 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:

  ```gleam
  type Person {
    Person(name: String, age: Int)
  }
  ```

  The following code used to be generated:

  ```gleam
  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:

  ```gleam
  fn encode_person(person: Person) -> json.Json {
    let Person(name:, age:) = person
    json.object([
      #("name", json.string(name)),
      #("age", json.int(age)),
    ])
  }
  ```

  ([Surya Rose](https://github.com/GearsDatapacks))

- The language server now supports finding references to values and types,
  both within a module and across multiple modules.
  ([Surya Rose](https://github.com/GearsDatapacks))

- The language server now offers a code action to remove all `echo`s in a
  module. For example:

  ```gleam
  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 `echo` pipeline steps:

  ```gleam
  pub fn main() {
    [1, 2, 3]
    |> list.filter(int.is_even)
  }
  ```

  This also works with all the `echo`s used before an expression:

  ```gleam
  pub fn main() {
    echo 1 + 2
  //^^^^^^^^^^ If hovering anywhere over here
  }
  ```

  Triggering the code action would remove the `echo`:

  ```gleam
  pub fn main() {
    1 + 2
  }
  ```

  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- The language server now offers the option to lift expressions into consts.
  For example, in two uses of the code action:

  ```gleam
  pub fn main() {
    [#("a", 0), #("b", 1), #("a", 2)]
    |> key_filter("a")
  }
  ```

  Becomes:

  ```gleam
  const values = [#("a", 0), #("b", 1), #("a", 2)]

  const string = "a"

  pub fn main() {
    values
    |> key_filter(string)
  }
  ```

  ([Matias Carlander](https://github.com/matiascr))

- The language server will now only offer the code action to generate a JSON
  encoder if the `gleam_json` package is installed as a dependency.
  ([Surya Rose](https://github.com/GearsDatapacks))

### Formatter

### Bug fixes

- Fixed a bug where tuples with atoms in the first position could be
  incorrectly formatted by `echo`.
  ([Louis Pilfold](https://github.com/lpil))

- Fixed a bug where unlabelled arguments would be allowed after labelled
  arguments in variant constructor definitions.
  ([Surya Rose](https://github.com/GearsDatapacks))

- 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](https://github.com/giacomocavalieri))

- Fixed a bug where using the "Convert to pipe" code action on a function or
  record capture produces invalid code.
  ([Matias Carlander](https://github.com/matiascr))

- Fixed a bug where the "Inline variable" code action would not work properly
  if used inside a record update.
  ([Surya Rose](https://github.com/GearsDatapacks))

- Fixed a bug where variant inference wouldn't work on `let assert` assignments.
  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the build tool could fail to lock the build directory but
  not report an error.
  ([Louis Pilfold](https://github.com/lpil))

- 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](https://github.com/lpil))

- Fixed a bug where `let assert` would not assert that the given value matched
  the pattern if it was the only expression inside a block.
  ([Surya Rose](https://github.com/GearsDatapacks))

- Fixed a bug where the code generated for `echo` on JavaScript could have name
  collisions if there are functions called `console` or `process`, or custom type
  variants called `Object` or `Deno` defined in the module.
  ([Louis Pilfold](https://github.com/lpil))

## v1.9.1 - 2025-03-10

### Formatter

- Improved the formatting of pipelines printed with `echo`.
  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))

### Bug fixes

- Fixed a bug where `echo` used before a pipeline would generate invalid code
  for the Erlang target.
  ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
