Skip to content

Commit

Permalink
maps:fold snapshot tests with occurrence typing
Browse files Browse the repository at this point in the history
Summary: As title, occurrence typing is not supported for `maps:fold` yet.

Reviewed By: ilya-klyuchnikov

Differential Revision: D65658020

fbshipit-source-id: cae7b99ee61cbeefc592d75275b96b155ed5145f
  • Loading branch information
VLanvin authored and facebook-github-bot committed Nov 12, 2024
1 parent 114df71 commit bf535c4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 13 deletions.
60 changes: 47 additions & 13 deletions crates/elp/src/resources/test/eqwalizer_tests/check/custom.pretty
Original file line number Diff line number Diff line change
Expand Up @@ -2230,9 +2230,43 @@ See https://fb.me/eqwalizer_errors#incompatible_types
'something' is not compatible with 'iodata' | 'list' | 'binary'

error: incompatible_types
┌─ check/src/custom.erl:2470:5
┌─ check/src/custom.erl:2467:34
2470 │ lists:partition(fun is_number/1, L).
2467 │ (_, V, Acc) -> Acc + V
│ ^
│ │
│ V.
Expression has type: number() | 'undefined'
Context expected type: number()

See https://fb.me/eqwalizer_errors#incompatible_types

number() | 'undefined' is not compatible with number()
because
'undefined' is not compatible with number()

error: incompatible_types
┌─ check/src/custom.erl:2480:28
2480 │ (_, V, Acc) -> Acc + V
│ ^^^
│ │
│ Acc.
Expression has type: number() | 'undefined'
Context expected type: number()

See https://fb.me/eqwalizer_errors#incompatible_types

number() | 'undefined' is not compatible with number()
because
'undefined' is not compatible with number()

error: incompatible_types
┌─ check/src/custom.erl:2496:5
2496 │ lists:partition(fun is_number/1, L).
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ │
│ lists:partition(fun, L).
Expand All @@ -2250,9 +2284,9 @@ See https://fb.me/eqwalizer_errors#incompatible_types
number() is not compatible with atom()

error: incompatible_types
┌─ check/src/custom.erl:2482:5
┌─ check/src/custom.erl:2508:5
2482 │ lists:partition(fun({_Term, V}) -> is_number(V) end, L).
2508 │ lists:partition(fun({_Term, V}) -> is_number(V) end, L).
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ │
│ lists:partition(fun, L).
Expand All @@ -2273,9 +2307,9 @@ See https://fb.me/eqwalizer_errors#incompatible_types
number() is not compatible with atom()

error: incompatible_types
┌─ check/src/custom.erl:2500:5
┌─ check/src/custom.erl:2526:5
2500 │ lists:partition(fun({ok, _}) -> true; (_) -> false end, L).
2526 │ lists:partition(fun({ok, _}) -> true; (_) -> false end, L).
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ │
│ lists:partition(fun, L).
Expand All @@ -2296,9 +2330,9 @@ See https://fb.me/eqwalizer_errors#incompatible_types
{'ok', atom()} is not compatible with {'error', term()}

error: incompatible_types
┌─ check/src/custom.erl:2540:33
┌─ check/src/custom.erl:2566:33
2540 │ maps_intersect_2_neg(M1, M2) -> maps:intersect(M1, M2).
2566 │ maps_intersect_2_neg(M1, M2) -> maps:intersect(M1, M2).
│ ^^^^^^^^^^^^^^^^^^^^^^
│ │
│ maps:intersect(M1, M2).
Expand All @@ -2311,9 +2345,9 @@ See https://fb.me/eqwalizer_errors#incompatible_types
key `a` is declared as required in the latter but not in the former

error: incompatible_types
┌─ check/src/custom.erl:2550:33
┌─ check/src/custom.erl:2576:33
2550 │ maps_intersect_4_neg(M1, M2) -> maps:intersect(M1, M2).
2576 │ maps_intersect_4_neg(M1, M2) -> maps:intersect(M1, M2).
│ ^^^^^^^^^^^^^^^^^^^^^^
│ │
│ maps:intersect(M1, M2).
Expand All @@ -2331,9 +2365,9 @@ See https://fb.me/eqwalizer_errors#incompatible_types
number() is not compatible with 'true'

error: incompatible_types
┌─ check/src/custom.erl:2560:33
┌─ check/src/custom.erl:2586:33
2560 │ maps_intersect_6_neg(M1, M2) -> maps:intersect(M1, M2).
2586 │ maps_intersect_6_neg(M1, M2) -> maps:intersect(M1, M2).
│ ^^^^^^^^^^^^^^^^^^^^^^
│ │
│ maps:intersect(M1, M2).
Expand All @@ -2345,4 +2379,4 @@ See https://fb.me/eqwalizer_errors#incompatible_types

key `a` is declared as required in the latter but not in the former

163 ERRORS
165 ERRORS
26 changes: 26 additions & 0 deletions test_projects/eqwalizer_tests/check/src/custom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,32 @@ maps_fold_no_merge(M1, M2, B) ->
),
Res.

-spec maps_fold_occ_1
(M1 :: #{number() => number() | undefined})
-> number().
maps_fold_occ_1(M1) ->
maps:fold(
fun
(_, undefined, Acc) -> Acc;
(_, V, Acc) -> Acc + V
end,
0,
M1
).

-spec maps_fold_occ_2
(M1 :: #{number() => number()}, AccInit :: number() | undefined)
-> number() | undefined.
maps_fold_occ_2(M1, AccInit) ->
maps:fold(
fun
(_, V, undefined) -> V;
(_, V, Acc) -> Acc + V
end,
AccInit,
M1
).

-spec lists_partition_rid
(L :: [atom() | number()])
-> {[atom()], [number()]}.
Expand Down

0 comments on commit bf535c4

Please sign in to comment.