You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+42-8Lines changed: 42 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@
8
8
9
9
## Type system improvements
10
10
11
-
### Full type inference
11
+
This release includes type inference of all constructs.
12
+
13
+
### Type inference of function calls
12
14
13
15
Elixir now performs inference of whole functions. The best way to show the new capabilities are with examples. Take the following code:
14
16
@@ -30,6 +32,42 @@ end
30
32
31
33
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.
32
34
35
+
### Type inference of guards
36
+
37
+
This release also performs inference of guards! Let's see some examples:
38
+
39
+
```elixir
40
+
defexample(x, y) whenis_list(x) andis_integer(y)
41
+
```
42
+
43
+
The code above correctly infers `x` is a list and `y` is an integer.
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
+
defexample(x) whenis_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
+
defexample(x) whennotis_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
+
defexample(x) whentuple_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, anduse this information to find bugs in our code, without a need to introduce type signatures (yet).
70
+
33
71
### Complete typing of maps keys
34
72
35
73
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:
116
154
└─ lib/calls_user.ex:7:5: CallsUser.calls_name/0
117
155
```
118
156
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
-
121
157
### Acknowledgements
122
158
123
159
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:/
131
167
* [Calendar] Optimize `date_from_iso_days` by using the Neri-Schneider algorithm
132
168
* [Enum] Add `Enum.min_max` sorter
133
169
* [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`
134
172
* [Kernel] Print intermediate results of `dbg` for pipes
135
173
* [Kernel] Warn on unused requires
136
174
* [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:/
0 commit comments