-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from xxdavid/fix_map_exhaustiveness
Improve map exhaustiveness checking
- Loading branch information
Showing
9 changed files
with
543 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
-module(map_refinement_fancy). | ||
|
||
-export([map_refinement_fancy/1]). | ||
-export([map_refinement_fancy/1, just_a_bit_less_fancy/1]). | ||
|
||
%% Expected exhustiveness error: Values of type #{1 := 3, 2 := 4} not covered. | ||
%% Expected exhaustiveness error: Values of type #{1 := 3, 2 := 4} not covered. | ||
%% | ||
%% Explanation: Currently, during refinement, after clause 1 a type with | ||
%% overlapping keys #{1..2 := 3, 2 := 3..4} is produced, which prevents | ||
%% exhaustiveness checking. It almost works. :) | ||
%% Explanation: exhaustiveness checking is disabled for maps with non-singleton | ||
%% required (exact assoc) keys. | ||
-spec map_refinement_fancy(#{1..2 := 3..4}) -> ok. | ||
map_refinement_fancy(#{1 := 4}) -> | ||
ok; | ||
map_refinement_fancy(#{2 := 3}) -> | ||
ok. | ||
|
||
%% Expected exhaustiveness error: Values #{x => a} and #{y => a} not covered. | ||
%% | ||
%% Explanation: exhaustiveness checking is disabled for maps with non-singleton | ||
%% required (exact assoc) keys. | ||
-spec just_a_bit_less_fancy(#{x|y := a}) -> ok. | ||
just_a_bit_less_fancy(#{x := a, y := a}) -> ok. |
22 changes: 22 additions & 0 deletions
22
test/known_problems/should_pass/inner_union_subtype_of_root_union.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-module(inner_union_subtype_of_root_union). | ||
|
||
-export([tuple_case/0, map_case/1]). | ||
|
||
% The problem is that {t, a|b} is not subtype of {t, a} | {t, b}. | ||
|
||
% It has surfaced because | ||
% {'type', anno(), 'map_field_assoc' | 'map_field_exact', [abstract_type()]} | ||
% is not a subtype of | ||
% {'type', anno(), 'map_field_assoc', [abstract_type()]} | ||
% | {'type', anno(), 'map_field_exact', [abstract_type()]} | ||
|
||
-spec g() -> a | b. | ||
g() -> a. | ||
|
||
-spec tuple_case() -> {t, a} | {t, b}. | ||
tuple_case() -> | ||
{t, g()}. | ||
|
||
% The same thing holds for maps. | ||
-spec map_case(#{a => b | c}) -> #{a => b} | #{a => c}. | ||
map_case(M) -> M. |
7 changes: 7 additions & 0 deletions
7
test/known_problems/should_pass/map_pattern_duplicate_key.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-module(map_pattern_duplicate_key). | ||
|
||
-export([f/1]). | ||
|
||
% Fails with: The expression x on line 6 at column 13 is not a valid key in the map type #{x := a} | ||
-spec f(#{x := a}) -> true. | ||
f(#{x := a, x := a}) -> true. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters