Skip to content

Commit 484e14f

Browse files
ruippeixotogfacebook-github-bot
authored andcommitted
Dedup keys when parsing shape maps in ELP
Summary: The Erlang spec allows users to define map types with duplicate keys, wherte the leftmost definition takes precedence. This will be later disallowed in eqWAlizer, but for now, we need to ensure parsing deals with these cases correctly. Reviewed By: ilya-klyuchnikov, VLanvin Differential Revision: D59802368 fbshipit-source-id: f551fe2503b1a0e75e998bc732abefb1317bbffa
1 parent 1b662eb commit 484e14f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

eqwalizer/src/main/scala/com/whatsapp/eqwalizer/ast/ConvertTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ConvertTypes(module: String) {
128128
case prop @ OptExtProp(AtomLitExtType(key), _) => (key, prop)
129129
}
130130
val isShape = atomKeyedProps.size == props.size
131-
if (isShape) ShapeMap(atomKeyedProps.map(toShapeProps(s, _)))
131+
if (isShape) ShapeMap(atomKeyedProps.distinctBy(_._1).map(toShapeProps(s, _)))
132132
else DictMap(c(props.head.key), c(props.head.tp))
133133
case BuiltinExtType(name) =>
134134
builtinTypes(name)

eqwalizer/test_projects/check/src/other.erl

+3
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ any_as_metadata_neg(M) -> M.
4949
elab_var_scope(_) ->
5050
(begin X = 3, X, fun () -> ok end end)(),
5151
X.
52+
53+
-spec map_with_dup_keys(#{ak => av1, bk => bv1, ak => av2}) -> #{ak => av1, bk => bv1}.
54+
map_with_dup_keys(M) -> M.

eqwalizer/test_projects/check/src/other.erl.check

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ any_as_metadata_neg(M) -> M. | ERROR | M.
5757
elab_var_scope(_) -> | OK |
5858
(begin X = 3, X, fun () -> ok end end)…… |
5959
X. | |
60+
| |
61+
-spec map_with_dup_keys(#{ak => av1, bk =>…… |
62+
map_with_dup_keys(M) -> M. | OK |

0 commit comments

Comments
 (0)