Skip to content

Commit c7884ca

Browse files
eksperimentaljosevalim
authored andcommitted
Elixir v1.19 introduces a warning related to structs, (#14818)
hint: given pattern matching is enough to catch typing errors, you may optionally convert the struct update into a map update. For example, instead of: user = some_fun() %User{user | name: "John Doe"} it is enough to write: %User{} = user = some_fun() %{user | name: "John Doe"} Since this could be seen by new-comers to the language, offering a better user experience by avoiding abbreviations. Favoring the usage of "some_function" instead of "some_fun"
1 parent 6f3fb27 commit c7884ca

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

lib/elixir/lib/module/types/expr.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,12 +849,12 @@ defmodule Module.Types.Expr do
849849
you may optionally convert the struct update into a map update. For \
850850
example, instead of:
851851
852-
user = some_fun()
852+
user = some_function()
853853
%User{user | name: "John Doe"}
854854
855855
it is enough to write:
856856
857-
%User{} = user = some_fun()
857+
%User{} = user = some_function()
858858
%{user | name: "John Doe"}
859859
"""
860860
])

lib/elixir/lib/task.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,17 @@ defmodule Task do
448448
the code before async/await has the same properties after you
449449
add the async call. For example, imagine you have this:
450450
451-
x = heavy_fun()
452-
y = some_fun()
451+
x = heavy_function()
452+
y = some_function()
453453
x + y
454454
455-
Now you want to make the `heavy_fun()` async:
455+
Now you want to make the `heavy_function()` async:
456456
457-
x = Task.async(&heavy_fun/0)
458-
y = some_fun()
457+
x = Task.async(&heavy_function/0)
458+
y = some_function()
459459
Task.await(x) + y
460460
461-
As before, if `heavy_fun/0` fails, the whole computation will
461+
As before, if `heavy_function/0` fails, the whole computation will
462462
fail, including the caller process. If you don't want the task
463463
to fail then you must change the `heavy_fun/0` code in the
464464
same way you would achieve it if you didn't have the async call.

lib/elixir/pages/getting-started/debugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ after: [2, 4, 6]
5050
It is also very common to use `IO.inspect/2` with `binding/0`, which returns all variable names and their values:
5151

5252
```elixir
53-
def some_fun(a, b, c) do
53+
def some_function(a, b, c) do
5454
IO.inspect(binding())
5555
...
5656
end
5757
```
5858

59-
When `some_fun/3` is invoked with `:foo`, `"bar"`, `:baz` it prints:
59+
When `some_function/3` is invoked with `:foo`, `"bar"`, `:baz` it prints:
6060

6161
```elixir
6262
[a: :foo, b: "bar", c: :baz]

lib/elixir/test/elixir/module/types/expr_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,12 @@ defmodule Module.Types.ExprTest do
964964
965965
hint: given pattern matching is enough to catch typing errors, you may optionally convert the struct update into a map update. For example, instead of:
966966
967-
user = some_fun()
967+
user = some_function()
968968
%User{user | name: "John Doe"}
969969
970970
it is enough to write:
971971
972-
%User{} = user = some_fun()
972+
%User{} = user = some_function()
973973
%{user | name: "John Doe"}
974974
"""
975975

0 commit comments

Comments
 (0)