Skip to content

Latest commit

 

History

History
363 lines (272 loc) · 9.88 KB

CHANGELOG.md

File metadata and controls

363 lines (272 loc) · 9.88 KB

Changelog

Unreleased

Compiler

  • The compiler can now tell if some branches with bit array patterns are unreachable. For example, the following code:

    case payload {
      <<first_byte, _:bits>> -> first_byte
      <<1, _:bits>> -> 1
      _ -> 0
    }

    Will raise the following warning:

    warning: Unreachable case clause
      ┌─ /src/bit_array.gleam:4:5
      │
    4 │     <<1, _:bits>> -> 1
      │     ^^^^^^^^^^^^^^^^^^
    This case clause cannot be reached as a previous clause matches the same
    values.
    Hint: It can be safely removed.
    

    (Giacomo Cavalieri)

  • The compiler now raises a warning when it can tell that an integer segment with a literal value is going to be truncated. For example, if you wrote this:

    <<258>>

    The compiler will now warn you:

    warning: Truncated bit array segment
      ┌─ /src/main.gleam:4:5
      │
    4 │   <<258>>
      │     ^^^ You can safely replace this with 2
    
    This segment is 1 byte long, but 258 doesn't fit in that many bytes. It
    would be truncated by taking its its first byte, resulting in the value 2.

    (Giacomo Cavalieri)

  • The compiler will now include labels in the error message when a case expression is inexhaustive. For example, this code:

    pub type Person {
      Person(name: String, age: Int)
    }
    
    pub fn classify(person: Person) {
      case person {
        Person(name: "John", age: 27) -> todo
        Person(name: _, age: 42) -> todo
      }
    }

    Will produces this error:

    error: Inexhaustive patterns
      ┌─ /src/main.gleam:6:3
      │
    6 │ ╭   case person {
    7 │ │     Person(name: "John", age: 27) -> todo
    8 │ │     Person(name: _, age: 42) -> todo
    9 │ │   }
      │ ╰───^
    
    This case expression does not have a pattern for all possible values. If it
    is run on one of the values without a pattern then it will crash.
    
    The missing patterns are:
    
        Person(name:, age:)
    

    (Surya Rose)

  • The analysis of lists, tuples, negation operators, panic, echo and todo is now fault tolerant, meaning that the compiler will not stop reporting errors as soon as it finds one. (Giacomo Cavalieri)

  • The error message for types used with the wrong number of arguments has been improved. For example, this piece of code:

    type Wibble(a)
    
    type Wobble {
      Wobble(Wibble)
    }

    Produces the following error:

      error: Incorrect arity
      ┌─ /src/one/two.gleam:5:10
      │
    5 │   Wobble(Wibble)
      │          ^^^^^^ Expected 1 type argument, got 0
    
    `Wibble` requires 1 type argument but none where provided.

    (Giacomo Cavalieri)

  • You can now use the assert keyword by itself to test a boolean expression. If the expression evaluates to False at runtime, the assert statement will cause the program to panic, with information about the expression that was asserted.

    For example:

    pub fn ok_error_test() {
      assert result.is_ok(Ok(10))
      assert result.is_error(Error("Some error"))
      assert Ok(1) != Error(1)
      assert result.is_error(Ok(42)) // panic: Assertion failed
    }

    A custom panic message can also be provided in order to add extra information:

    pub fn identity_test() {
      assert function.identity(True) as "Identity of True should never be False"
    }

    (Surya Rose)

  • The compiler will now emit a warning when the return value of a call to a function without side effects is unused. For example the following code:

    fn add(a, b) { a + b }

    Will produce the following warning:

    warning: Unused value
      ┌─ /src/main.gleam:4:3
      │
    4 │   add(1, 2)
      │   ^^^^^^^^^ This value is never used
    
    This expression computes a value without any side effects, but then the
    value isn't used at all. You might way to assign it to a variable, or
    delete the expression entirely if it not needed.
    

    (Surya Rose)

  • The compiler will now generate more efficient code for let assert on the Erlang target. (Surya Rose)

Build tool

  • The build tool now supports placing modules in a directory called dev, which like test, is only for development code. (Surya Rose)

  • There is now a new CLI command, gleam dev, which runs the $PACKAGE_dev module, for running development entrypoints. (Surya Rose)

  • Updated the Erlang shipment POSIX entrypoint script to add an exec statement so the Erlang process replaces the shell's process and can receive signals when deployed. (Christopher De Vries)

  • The build tool now provides additional information when printing warnings for deprecated environment variables. (Surya Rose)

Language server

  • The code action to add missing labels to function now also works in patterns:

    pub type Person {
      Person(name: String, age: Int, job: String)
    }
    
    pub fn age(person: Person) {
      let Person(age:) = person
      age
    }

    Becomes:

    pub type Person {
      Person(name: String, age: Int, job: String)
    }
    
    pub fn age(person: Person) {
      let Person(age:, name:, job:) = person
      age
    }

    (Surya Rose)

  • The JSON encoding function that the language server code action generates is now named $TYPENAME_to_json instead of encode_$TYPENAME. This is to remove ambiguity with functions that encode to other formats, and to make the function easier to discover by searching.

    (Louis Pilfold)

  • The code action to add missing patterns to a case expression now includes labels in the generated patterns. For example:

    pub type Person {
      Person(name: String, age: Int)
    }
    
    pub fn classify(person: Person) {
      case person {
        Person(name: "John", age: 27) -> todo
        Person(name: _, age: 42) -> todo
      }
    }

    Will now become:

    pub type Person {
      Person(name: String, age: Int)
    }
    
    pub fn classify(person: Person) {
      case person {
        Person(name: "John", age: 27) -> todo
        Person(name: _, age: 42) -> todo
        Person(name:, age:) -> todo
      }
    }

    (Surya Rose)

  • The language server now provides hover, autocomplete and goto definition for constant definitions. (Surya Rose)

  • The "generate function" code action can now choose better names based on the labels and variables used. For example if I write the following code:

    pub fn main() -> List(Int) {
      let list = [1, 2, 3]
      let number = 1
      remove(each: number, in: list)
    //^^^^ This function doesn't exist yet!
    }

    And ask the language server to generate the missing function, the generated code will now look like this:

    fn remove(each number: Int, in list: List(Int)) -> List(Int) {
      todo
    }

    (Giacomo Cavalieri)

  • The language server now provides autocomplete suggestions for labels after part of the label has already been typed. For example, in this code:

    pub type Person {
      Person(name: String, number: Int)
    }
    
    pub fn main() {
      Person(n|)
    }

    The language server will provide name: and number: as autocomplete suggestions.

    (Surya Rose)

Formatter

Installation

Bug fixes

  • Fixed a bug where case expressions in custom panic messages would compile to invalid syntax on the JavaScript target. (Surya Rose)

  • Fixed a bug where case expressions in custom panic messages would compile to invalid syntax on the JavaScript target. (Surya Rose)

  • Fixed a bug where an underscore after a zero in a number would compile to invalid syntax on the JavaScript target. (Surya Rose)

  • Fixed a bug where the "generate function" code action could generate invalid code when the same variable was passed as an argument twice. (Giacomo Cavalieri)

  • Fixed a bug where replacing a Hex dependency with a Git dependency of the same name would cause the build tool to fail. (Surya Rose)

  • Fixed a bug where updating the remote URL of a Git dependency would fail to update the remote in the local dependency, causing a caching issue. (Surya Rose)

  • Fix slightly wrong error message for missing main function in test module. (Samuel Cristobal)

  • Fixed a bug where the compiler would not properly warn for unreachable patterns in a case expression when the clause matched on multiple alternative patterns. (Surya Rose)

  • Fixed a bug where the language server would generate invalid code for the "fill in missing labels" code action. (Giacomo Cavalieri)

  • Fixed a bug where referencing an earlier segment of the bit array in a bit array pattern in a let assert assignment would generate invalid code on the Erlang target. (Surya Rose)

  • Fixed instances where the "Extract variable" code action would produce invalid code, most noticeable in code inside case clauses and use expressions. (Matias Carlander)