-
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 #434 from erszcz/lc-generators-being-none
Add examples of list comprehension generators being none()
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
test/known_problems/should_pass/lc_cannot_glb_different_variants.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(lc_cannot_glb_different_variants). | ||
|
||
%% Compare with: | ||
%% - test/should_fail/lc_generator_should_fail.erl | ||
%% - test/should_pass/lc_generator_not_none.erl | ||
|
||
-export([g/2]). | ||
|
||
-type t() :: {a, d} | ||
| {a, [t()]}. | ||
|
||
-spec g(integer(), t()) -> [t()]. | ||
g(1, {a, d} = T) -> | ||
[T]; | ||
g(_, {a, Ts}) -> | ||
%% `typechecker:add_type_pat({a, Ts}, {a, d} | {a, [t()]}, Env)' at `typechecker.erl:4310' | ||
%% calls `glb(d, [t()])' to find the type of `Ts'. | ||
%% The call determines that `Ts :: none()', as `d' and `[t()]' are incompatible. | ||
%% This leads to a warning being reported for the following line. | ||
[ T || T <- Ts ]; | ||
g(_, _) -> | ||
[]. |
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,20 @@ | ||
-module(lc_generator_should_fail). | ||
|
||
%% Compare with: | ||
%% - test/known_problems/should_pass/lc_cannot_glb_different_variants.erl | ||
%% - test/should_pass/lc_generator_not_none.erl | ||
|
||
-export([g/1]). | ||
|
||
-type t() :: {a, d} | ||
| {a, [t()]}. | ||
|
||
-spec g(t()) -> [t()]. | ||
g({a, Ts}) -> | ||
%% If we didn't use a list comprehension and just returned an empty list, | ||
%% this would rightly fail with a nonexhaustiveness warning. | ||
%[]. | ||
%% If we use a comprehension, glb(d, [t()]) determines that Ts :: none(). | ||
%% This glb() call is done from typechecker:add_type_pat({a, Ts}, {a, d} | {a, [t()]}, Env) | ||
%% at typechecker.erl:4310 | ||
[ T || T <- Ts ]. |
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,16 @@ | ||
-module(lc_generator_not_none). | ||
|
||
%% Compare with: | ||
%% - test/known_problems/should_pass/lc_cannot_glb_different_variants.erl | ||
%% - test/should_fail/lc_generator_should_fail.erl | ||
|
||
-export([g/1]). | ||
|
||
-type t() :: {a, d} | ||
| {a, [t()]}. | ||
|
||
-spec g(t()) -> [t()]. | ||
g({a, d} = T) -> | ||
[T]; | ||
g({a, Ts}) -> | ||
[ T || T <- Ts ]. |