Skip to content

Commit

Permalink
[typer] only check constants for duplicate map key detection
Browse files Browse the repository at this point in the history
closes #9144
  • Loading branch information
Simn committed Jun 5, 2020
1 parent 915daa0 commit 7975601
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,10 @@ and type_map_declaration ctx e1 el with_type p =
display_error ctx "Duplicate key" e_key.epos;
error "Previously defined here" p
with Not_found ->
Hashtbl.add keys e_key.eexpr e_key.epos;
begin match e_key.eexpr with
| TConst _ -> Hashtbl.add keys e_key.eexpr e_key.epos;
| _ -> ()
end
in
let el = e1 :: el in
let el_kv = List.map (fun e -> match fst e with
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/src/unit/issues/Issue9144.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package unit.issues;

class Issue9144 extends Test {
function test() {
var i = 1;
var x:Map<Int, Int> = [i => (i = 2), i => 3];
eq(2, x[1]);
eq(3, x[2]);
}
}

0 comments on commit 7975601

Please sign in to comment.