Skip to content

Commit 52857fb

Browse files
VLanvinmeta-codesync[bot]
authored andcommitted
Fix error message heuristic on unions of maps
Summary: The heuristic uses a score of 50 as the limit for a partial match in a union, but partial matches on maps can go as low as 40. Change the limit to be 40 for both, so that a candidate map is always selected. Reviewed By: TD5 Differential Revision: D85868725 fbshipit-source-id: 60b1bfda0f58642bda144ac1e3bf2389523101e7
1 parent 37e8492 commit 52857fb

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

crates/elp/src/resources/test/eqwalizer_tests/check/custom-OTP-26.pretty

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ Expression has type: #{'a' | 'b' => atom() | number()}
792792
Context expected type: #{a := atom(), b := number()} | #{a := atom()}
793793
794794

795+
Because in the expression's type:
796+
Here the type is: #{...}
797+
Context expects type: #{a := ..., b := ..., ...}
798+
The type of the expression is missing the following required keys: a, b.
799+
800+
------------------------------ Detailed message ------------------------------
801+
795802
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()} | #{a := atom()}
796803
because
797804
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()}

crates/elp/src/resources/test/eqwalizer_tests/check/custom-OTP-27.pretty

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ Expression has type: #{'a' | 'b' => atom() | number()}
792792
Context expected type: #{a := atom(), b := number()} | #{a := atom()}
793793
794794

795+
Because in the expression's type:
796+
Here the type is: #{...}
797+
Context expects type: #{a := ..., b := ..., ...}
798+
The type of the expression is missing the following required keys: a, b.
799+
800+
------------------------------ Detailed message ------------------------------
801+
795802
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()} | #{a := atom()}
796803
because
797804
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()}

crates/elp/src/resources/test/eqwalizer_tests/check/custom-OTP-28.pretty

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ Expression has type: #{'a' | 'b' => atom() | number()}
792792
Context expected type: #{a := atom(), b := number()} | #{a := atom()}
793793
794794

795+
Because in the expression's type:
796+
Here the type is: #{...}
797+
Context expects type: #{a := ..., b := ..., ...}
798+
The type of the expression is missing the following required keys: a, b.
799+
800+
------------------------------ Detailed message ------------------------------
801+
795802
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()} | #{a := atom()}
796803
because
797804
#{'a' | 'b' => atom() | number()} is not compatible with #{a := atom(), b := number()}

crates/elp/src/resources/test/eqwalizer_tests/check/error_messages.pretty

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ Context expected type: #{foo => #{large_map_key_c => 'large_map_val_c'} | #{larg
138138

139139
Because in the expression's type:
140140
#{ foo =>
141-
Here the type is: #{...}
142-
Context expects type: #{...} | #{...}
143-
No candidate matches in the expected union.
141+
Here the type is: #{large_map_key_a => ...}
142+
Context expects type: #{...}
143+
The expected map has no corresponding key for: large_map_key_a.
144144
, ... }
145145

146146
------------------------------ Detailed message ------------------------------
@@ -168,9 +168,9 @@ Context expected type: #{foo => #{large_map_key_c => 'large_map_val_c', large_ma
168168

169169
Because in the expression's type:
170170
#{ foo =>
171-
Here the type is: #{...}
172-
Context expects type: #{...} | 'any'
173-
No candidate matches in the expected union.
171+
Here the type is: #{large_map_key_a => ...}
172+
Context expects type: #{...}
173+
The expected map has no corresponding key for: large_map_key_a.
174174
, ... }
175175

176176
------------------------------ Detailed message ------------------------------

crates/elp/src/resources/test/eqwalizer_tests/check/opaque.pretty

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ Context expected type: sets:set({'ok', 'ok'})
1010
1111

1212
Because in the expression's type:
13-
Here the type is a union type with some valid candidates: #set{}
14-
However the following candidate: #{{ok, error} => []}
15-
Differs from the expected type: #set{} | #{{ok, ok} => []}
13+
The type is a union type with some valid candidates: #set{}
14+
However, the following candidate doesn't match:
15+
Here the type is: #{{ok, error} => ...}
16+
Context expects type: #{...}
17+
The expected map has no corresponding key for: {ok, error}.
1618

1719
------------------------------ Detailed message ------------------------------
1820

crates/elp/src/resources/test/eqwalizer_tests/check/recursive_aliases.pretty

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ Context expected type: mChainA()
166166
167167

168168
Because in the expression's type:
169-
Here the type is a union type with some valid candidates: 'nil'
170-
However the following candidate: #{b := mChainB()}
171-
Differs from the expected type: 'nil' | #{a := mChainA()}
169+
The type is a union type with some valid candidates: 'nil'
170+
However, the following candidate doesn't match:
171+
Here the type is: #{...}
172+
Context expects type: #{a := ..., ...}
173+
The type of the expression is missing the following required keys: a.
172174

173175
------------------------------ Detailed message ------------------------------
174176

0 commit comments

Comments
 (0)