Skip to content

Commit 85b5838

Browse files
committed
Ensure %_{} is precise in guards, closes #15635
1 parent f16d8d2 commit 85b5838

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/elixir/lib/module/types/pattern.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@ defmodule Module.Types.Pattern do
777777

778778
if compatible?(refined, atom()) do
779779
fields = [__struct__: {refined, false}]
780-
of_open_map(args, singleton?(refined), fields, [], path, stack, context)
780+
precise? = match?({:_, _, _}, var) or singleton?(refined)
781+
of_open_map(args, precise?, fields, [], path, stack, context)
781782
else
782783
error = {:badstruct, refined, expr, context}
783784
{error_type(), false, error(__MODULE__, error, meta, stack, context)}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,11 @@ defmodule Module.Types.PatternTest do
14141414
end
14151415

14161416
test "maps in patterns" do
1417+
assert precise?([%{}])
14171418
assert precise?([%{ok: _}])
1419+
assert precise?([%_{}])
1420+
assert precise?([%x{}])
1421+
assert precise?([%URI{}])
14181422
assert precise?([%URI{path: _}])
14191423

14201424
refute precise?([%{ok: 123}])

0 commit comments

Comments
 (0)