|
5 | 5 |
|
6 | 6 | expand_map(Meta, [{'|', UpdateMeta, [Left, Right]}], E) ->
|
7 | 7 | {[ELeft|ERight], EA} = elixir_exp:expand_args([Left|Right], E),
|
| 8 | + validate_kv(Meta, ERight, Right, E), |
8 | 9 | {{'%{}', Meta, [{'|', UpdateMeta, [ELeft, ERight]}]}, EA};
|
9 | 10 | expand_map(Meta, Args, E) ->
|
10 | 11 | {EArgs, EA} = elixir_exp:expand_args(Args, E),
|
| 12 | + validate_kv(Meta, EArgs, Args, E), |
11 | 13 | {{'%{}', Meta, EArgs}, EA}.
|
12 | 14 |
|
13 | 15 | expand_struct(Meta, Left, Right, E) ->
|
@@ -35,6 +37,15 @@ expand_struct(Meta, Left, Right, E) ->
|
35 | 37 |
|
36 | 38 | {{'%', EMeta, [ELeft, ERight]}, EE}.
|
37 | 39 |
|
| 40 | +validate_kv(Meta, KV, Original, E) -> |
| 41 | + lists:foldl(fun |
| 42 | + ({_K, _V}, Acc) -> Acc + 1; |
| 43 | + (_, Acc) -> |
| 44 | + compile_error(Meta, ?m(E, file), |
| 45 | + "expected key-value pairs in a map, got: ~ts", |
| 46 | + ['Elixir.Macro':to_string(lists:nth(Acc, Original))]) |
| 47 | + end, 1, KV). |
| 48 | + |
38 | 49 | translate_map(Meta, Args, S) ->
|
39 | 50 | {Assocs, TUpdate, US} = extract_assoc_update(Args, S),
|
40 | 51 | translate_map(Meta, Assocs, TUpdate, US).
|
@@ -139,14 +150,10 @@ translate_map(Meta, Assocs, TUpdate, #elixir_scope{extra=Extra} = S) ->
|
139 | 150 |
|
140 | 151 | Line = ?line(Meta),
|
141 | 152 |
|
142 |
| - {TArgs, SA} = lists:mapfoldl(fun |
143 |
| - ({Key, Value}, Acc) -> |
144 |
| - {TKey, Acc1} = KeyFun(Key, Acc), |
145 |
| - {TValue, Acc2} = ValFun(Value, Acc1#elixir_scope{extra=Extra}), |
146 |
| - {{Op, ?line(Meta), TKey, TValue}, Acc2}; |
147 |
| - (Other, _Acc) -> |
148 |
| - compile_error(Meta, S#elixir_scope.file, "expected key-value pairs in map, got: ~ts", |
149 |
| - ['Elixir.Macro':to_string(Other)]) |
| 153 | + {TArgs, SA} = lists:mapfoldl(fun({Key, Value}, Acc) -> |
| 154 | + {TKey, Acc1} = KeyFun(Key, Acc), |
| 155 | + {TValue, Acc2} = ValFun(Value, Acc1#elixir_scope{extra=Extra}), |
| 156 | + {{Op, ?line(Meta), TKey, TValue}, Acc2} |
150 | 157 | end, S, Assocs),
|
151 | 158 |
|
152 | 159 | build_map(Line, TUpdate, TArgs, SA).
|
|
0 commit comments