Skip to content

Commit

Permalink
better shape keys in Narrow
Browse files Browse the repository at this point in the history
Reviewed By: VLanvin

Differential Revision: D53231278

fbshipit-source-id: 56dad4bcc6f600ab7937fab9427a7bb7f9643404
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Jan 31, 2024
1 parent 5fa669b commit 5a6c332
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Narrow(pipelineContext: PipelineContext) {
t match {
case DictMap(kt, _) => kt
case ShapeMap(Nil) => NoneType
case ShapeMap(_) => AtomType
case ShapeMap(kvs) => UnionType(Set(kvs.map(kv => AtomLitType(kv.key)): _*))
case UnionType(ts) => subtype.join(ts.map(getKeyType))
case NoneType => NoneType
case _ => throw new IllegalStateException()
Expand Down
12 changes: 3 additions & 9 deletions eqwalizer/test_projects/check/src/custom.erl.check
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ maps_map_2_9_neg() -> | ERROR |
M = #{a => a, b => b}, | |
F = fun erlang:'=:='/2, | |
maps:map(F, M). | | maps:map(F, M).
| | Expression has type: dict map #D{atom() => boolean()}
| | Expression has type: dict map #D{'a' | 'b' => boolean()}
| | Context expected type: shape map #S{a => 'a', b => 'b'}
| |
-spec maps_map_2_10_neg() | |
Expand Down Expand Up @@ -3083,15 +3083,9 @@ re_replace_6_neg(Subj) -> | ERROR |
Res. | |
| |
-spec maps_fold_keys(#{a => atom(), b => a…… |
maps_fold_keys(M) -> | ERROR |
maps_fold_keys(M) -> | OK |
maps:fold( | |
fun(K, _V, Acc) -> process_key(K),…… | K.
| | Expression has type: atom()
| | Context expected type: 'a' | 'b'
| |
| | atom() is not compatible with 'a' | 'b'
| | because
| | atom() is not compatible with 'a'
fun(K, _V, Acc) -> process_key(K),…… |
ok, | |
M | |
). | |
Expand Down
8 changes: 4 additions & 4 deletions eqwalizer/test_projects/check/src/t_maps.erl.check
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,15 @@ shape_atom_key(K, Shape) -> | OK |
shape_atom_key_neg(K, Shape) -> | ERROR |
case Shape of | |
#{K := V} -> {K, V}; | | {K, V}.
| | Expression has type: {atom(), a()}
| | Expression has type: {'a' | 'b', a()}
| | Context expected type: {n(), a()}
| |
| | at tuple index 1:
| | {atom(), a()} is not compatible with {n(), a()}
| | {'a' | 'b', a()} is not compatible with {n(), a()}
| | because
| | atom() is not compatible with n()
| | 'a' | 'b' is not compatible with n()
| | because
| | atom() is not compatible with number()
| | 'a' | 'b' is not compatible with number()
_ -> {0, undef} | |
end. | |
| |
Expand Down

0 comments on commit 5a6c332

Please sign in to comment.