Skip to content

Commit 867da6f

Browse files
author
José Valim
committed
Release v1.4.4
1 parent b2b974d commit 867da6f

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ You can now also install archives from Hex in this way. Since they are fetched a
109109

110110
It is also possible to install escripts and archives by providing a Git/GitHub repo. See `mix help escript.install` and `mix help archive.install` for more details.
111111

112+
## v1.4.4 (2017-05-15)
113+
114+
This version includes changes that make Elixir fully compatible with Erlang OTP 20-rc.1.
115+
116+
### 1. Bug fixes
117+
118+
#### Elixir
119+
120+
* [Map] Fix regression on struct update syntax
121+
112122
## v1.4.3 (2017-05-15)
113123

114124
This version includes changes that make Elixir fully compatible with Erlang OTP 20-rc.1.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.3
1+
1.4.4

lib/elixir/src/elixir_map.erl

+16-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,8 @@ expand_map(Meta, Args, E) ->
1313
{{'%{}', Meta, EArgs}, EA}.
1414

1515
expand_struct(Meta, Left, {'%{}', MapMeta, MapArgs}, #{context := Context} = E) ->
16-
CleanArgs =
17-
case lists:keytake('__struct__', 1, MapArgs) of
18-
{value, _, ValueArgs} ->
19-
elixir_errors:warn(?line(Meta), ?m(E, file),
20-
"key :__struct__ is ignored when building structs"),
21-
ValueArgs;
22-
false ->
23-
MapArgs
24-
end,
25-
26-
{[ELeft | EArgs], EE} = elixir_exp:expand_args([Left | CleanArgs], E),
27-
ERight = {'%{}', MapMeta, EArgs},
16+
CleanArgs = clean_struct_key_from_map_args(Meta, MapArgs, E),
17+
{[ELeft, ERight], EE} = elixir_exp:expand_args([Left, {'%{}', MapMeta, CleanArgs}], E),
2818

2919
case validate_struct(ELeft, Context) of
3020
true when is_atom(ELeft) ->
@@ -54,6 +44,20 @@ expand_struct(Meta, _Left, Right, E) ->
5444
compile_error(Meta, ?m(E, file), "expected struct to be followed by a map, got: ~ts",
5545
['Elixir.Macro':to_string(Right)]).
5646

47+
clean_struct_key_from_map_args(Meta, [{'|', PipeMeta, [Left, MapAssocs]}], E) ->
48+
[{'|', PipeMeta, [Left, clean_struct_key_from_map_assocs(Meta, MapAssocs, E)]}];
49+
clean_struct_key_from_map_args(Meta, MapAssocs, E) ->
50+
clean_struct_key_from_map_assocs(Meta, MapAssocs, E).
51+
52+
clean_struct_key_from_map_assocs(Meta, Assocs, E) ->
53+
case lists:keytake('__struct__', 1, Assocs) of
54+
{value, _, CleanAssocs} ->
55+
elixir_errors:warn(?line(Meta), ?m(E, file), "key :__struct__ is ignored when using structs"),
56+
CleanAssocs;
57+
false ->
58+
Assocs
59+
end.
60+
5761
validate_struct({'^', _, [{Var, _, Ctx}]}, match) when is_atom(Var), is_atom(Ctx) -> true;
5862
validate_struct({Var, _Meta, Ctx}, match) when is_atom(Var), is_atom(Ctx) -> true;
5963
validate_struct(Atom, _) when is_atom(Atom) -> true;

lib/elixir/test/elixir/kernel/warning_test.exs

+21
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,27 @@ defmodule Kernel.WarningTest do
781781
purge Sample
782782
end
783783

784+
defmodule User do
785+
defstruct [:name]
786+
end
787+
788+
test ":__struct__ is ignored when using structs" do
789+
assert capture_err(fn ->
790+
Code.eval_string """
791+
assert %Kernel.WarningTest.User{__struct__: Ignored, name: "joe"} ==
792+
%Kernel.WarningTest.User{name: "joe"}
793+
""", [], __ENV__
794+
end) =~ "key :__struct__ is ignored when using structs"
795+
796+
assert capture_err(fn ->
797+
Code.eval_string """
798+
user = %Kernel.WarningTest.User{name: "meg"}
799+
assert %Kernel.WarningTest.User{user | __struct__: Ignored, name: "joe"} ==
800+
%Kernel.WarningTest.User{__struct__: Kernel.WarningTest.User, name: "joe"}
801+
""", [], __ENV__
802+
end) =~ "key :__struct__ is ignored when using structs"
803+
end
804+
784805
defp purge(list) when is_list(list) do
785806
Enum.each list, &purge/1
786807
end

src/elixir.app.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, elixir,
22
[{description, "elixir"},
3-
{vsn, "1.4.3"},
3+
{vsn, "1.4.4"},
44
{modules, [
55
elixir
66
]},

0 commit comments

Comments
 (0)