Skip to content

Commit aa3dbdb

Browse files
committed
Ensure %_{} is precise in guards, closes #15635
1 parent a55c1f7 commit aa3dbdb

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
@@ -772,7 +772,8 @@ defmodule Module.Types.Pattern do
772772
{refined, context} = of_match_var(var, atom(), expr, stack, context)
773773

774774
if compatible?(refined, atom()) do
775-
of_open_map(args, singleton?(refined), [__struct__: refined], [], path, stack, context)
775+
precise? = match?({:_, _, _}, var) or singleton?(refined)
776+
of_open_map(args, precise?, [__struct__: refined], [], path, stack, context)
776777
else
777778
error = {:badstruct, refined, expr, context}
778779
{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
@@ -1386,7 +1386,11 @@ defmodule Module.Types.PatternTest do
13861386
end
13871387

13881388
test "maps in patterns" do
1389+
assert precise?([%{}])
13891390
assert precise?([%{ok: _}])
1391+
assert precise?([%_{}])
1392+
assert precise?([%x{}])
1393+
assert precise?([%URI{}])
13901394
assert precise?([%URI{path: _}])
13911395

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

0 commit comments

Comments
 (0)