Skip to content

Commit 583737d

Browse files
committed
Update CHANGELOG
1 parent 205a1ec commit 583737d

1 file changed

Lines changed: 42 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
## Type system improvements
1010

11-
### Full type inference
11+
This release includes type inference of all constructs.
12+
13+
### Type inference of function calls
1214

1315
Elixir now performs inference of whole functions. The best way to show the new capabilities are with examples. Take the following code:
1416

@@ -30,6 +32,42 @@ end
3032

3133
Even though the `+` operator works with both integers and floats, Elixir infers that `a` and `b` must be both integers, as the result of `+` is given to a function that expects an integer. The inferred type information is then used during type checking to find possible typing errors.
3234

35+
### Type inference of guards
36+
37+
This release also performs inference of guards! Let's see some examples:
38+
39+
```elixir
40+
def example(x, y) when is_list(x) and is_integer(y)
41+
```
42+
43+
The code above correctly infers `x` is a list and `y` is an integer.
44+
45+
```elixir
46+
def example({:ok, x} = y) when is_binary(x) or is_integer(x)
47+
```
48+
49+
The one above infers x is a binary or an integer, and `y` is a two element tuple with `:ok` as first element and a binary or integer as second.
50+
51+
```elixir
52+
def example(x) when is_map_key(x, :foo)
53+
```
54+
55+
The code above infers `x` is a map which has the `:foo` key, represented as `%{..., foo: dynamic()}`. Remember the leading `...` indicates the map may have other keys.
56+
57+
```elixir
58+
def example(x) when not is_map_key(x, :foo)
59+
```
60+
61+
And the code above infers `x` does not have the `:foo` key (hence `x.foo` will raise a typing violation), which has the type: `%{..., foo: not_set()}`.
62+
63+
You can also have expressions that assert on the size of data structures:
64+
65+
```elixir
66+
def example(x) when tuple_size(x) < 3
67+
```
68+
69+
Elixir will correctly track the tuple has at most two elements, and therefore accessing `elem(x, 3)` will emit a typing violation. In other words, Elixir can look at complex guards, infer types, and use this information to find bugs in our code, without a need to introduce type signatures (yet).
70+
3371
### Complete typing of maps keys
3472

3573
Maps were one of the first data-structures we implemented within the Elixir type system however, up to this point, they only supported atom keys. If they had additional keys, those keys were simply marked as `dynamic()`.
@@ -116,8 +154,6 @@ The code above has a type violation, which is now caught by the type system:
116154
└─ lib/calls_user.ex:7:5: CallsUser.calls_name/0
117155
```
118156
119-
Once again, our goal is to propagate type information and help developers find bugs in their code, without a need to introduce type signatures (yet).
120-
121157
### Acknowledgements
122158
123159
The type system was made possible thanks to a partnership between [CNRS](https://www.cnrs.fr/) and [Remote](https://remote.com/). The development work is currently sponsored by [Fresha](https://www.fresha.com/) and [Tidewave](https://tidewave.ai/).
@@ -131,6 +167,8 @@ The type system was made possible thanks to a partnership between [CNRS](https:/
131167
* [Calendar] Optimize `date_from_iso_days` by using the Neri-Schneider algorithm
132168
* [Enum] Add `Enum.min_max` sorter
133169
* [Integer] Add `Integer.ceil_div/2`
170+
* [IO] Add `IO.iodata_empty?/1`
171+
* [File] Skip device, named pipes, etc in `File.cp_r/3` instead of erroring with reason `:eio`
134172
* [Kernel] Print intermediate results of `dbg` for pipes
135173
* [Kernel] Warn on unused requires
136174
* [Regex] Add `Regex.import/1` to import regexes defined with `/E`
@@ -144,11 +182,7 @@ The type system was made possible thanks to a partnership between [CNRS](https:/
144182
* [mix deps] Support filtering `mix deps` output
145183
* [mix test] Add `mix test --dry-run`
146184
147-
### 2. Bug fixes
148-
149-
### 3. Soft deprecations (no warnings emitted)
150-
151-
### 4. Hard deprecations
185+
### 2. Hard deprecations
152186
153187
#### Elixir
154188

0 commit comments

Comments
 (0)