Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/elixir/src/elixir_map.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ translate_struct(Meta, Name, {'%{}', MapMeta, Args}, S) ->

{TMap, TS} = translate_map(MapMeta, Assocs, Var, VS),

{{'case', Ann, TUpdate, [
{{'case', ?generated, TUpdate, [
{clause, Ann, [Match], [], [TMap]},
{clause, Ann, [Var], [], [elixir_utils:erl_call(Ann, erlang, error, [Error])]}
{clause, ?generated, [Var], [], [elixir_utils:erl_call(Ann, erlang, error, [Error])]}
]}, TS};
match ->
translate_map(MapMeta, Assocs ++ [{'__struct__', Name}], nil, US);
Expand Down
7 changes: 7 additions & 0 deletions lib/elixir/test/elixir/fixtures/dialyzer/struct_update.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Dialyzer.StructUpdate do
defstruct [:foo]

def update(%__MODULE__{} = struct) do
%__MODULE__{struct | foo: :bar}
end
end
5 changes: 5 additions & 0 deletions lib/elixir/test/elixir/kernel/dialyzer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ defmodule Kernel.DialyzerTest do
assert_dialyze_no_warnings! context
end

test "no warnings on struct update", context do
copy_beam! context, Dialyzer.StructUpdate
assert_dialyze_no_warnings! context
end

defp copy_beam!(context, module) do
name = "#{module}.beam"
File.cp! Path.join(context[:base_dir], name),
Expand Down