Skip to content

Commit a5965ec

Browse files
VLanvinfacebook-github-bot
authored andcommitted
Snapshot -- imprecise error message with union of maps
Summary: An example where error messages choose a bad candidate with a union of maps. Reviewed By: sopotc Differential Revision: D69980767 fbshipit-source-id: 5b018000056cb33744b5cf4f859a41a1d1b0c519
1 parent bd0aea8 commit a5965ec

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
2+
┌─ check/src/error_messages.erl:16:22
3+
4+
16 │ map_candidates(M) -> M.
5+
│ ^
6+
│ │
7+
│ M.
8+
Expression has type: #{bar := atom(), baz := atom()}
9+
Context expected type: foo_map() | #{foo => atom()}
10+
11+
12+
Because in the expression's type:
13+
Here the type is: #{baz := ...}
14+
Context expects type: #{...}
15+
The expected map has no corresponding key for: baz.
16+
17+
------------------------------ Detailed message ------------------------------
18+
19+
#{bar := atom(), baz := atom()} is not compatible with foo_map() | #{foo => atom()}
20+
because
21+
#{bar := atom(), baz := atom()} is not compatible with foo_map()
22+
because
23+
#{bar := atom(), baz := atom()} is not compatible with #{bar => atom(), baz => number(), other => atom(), other2 => atom(), other3 => atom(), other4 => atom(), other5 => atom()}
24+
because
25+
at key `baz`:
26+
#{bar := atom(), baz := atom()} is not compatible with #{bar => atom(), baz => number(), other => atom(), other2 => atom(), other3 => atom(), other4 => atom(), other5 => atom()}
27+
28+
1 ERROR
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-module(error_messages).
2+
3+
-compile([export_all, nowarn_export_all]).
4+
5+
-type foo_map() :: #{
6+
bar => atom(),
7+
baz => integer(),
8+
other => atom(),
9+
other2 => atom(),
10+
other3 => atom(),
11+
other4 => atom(),
12+
other5 => atom()}.
13+
14+
-spec map_candidates(#{bar := atom(), baz := atom()}) ->
15+
foo_map() | #{foo => atom()}.
16+
map_candidates(M) -> M.

0 commit comments

Comments
 (0)