Browse Source

[typer] only check constants for duplicate map key detection

closes #9144
Simon Krajewski 5 years ago
parent
commit
79756011e2
2 changed files with 14 additions and 1 deletions
  1. 4 1
      src/typing/typer.ml
  2. 10 0
      tests/unit/src/unit/issues/Issue9144.hx

+ 4 - 1
src/typing/typer.ml

@@ -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

+ 10 - 0
tests/unit/src/unit/issues/Issue9144.hx

@@ -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]);
+	}
+}