Browse Source

constants uniqueness in switch

Nicolas Cannasse 18 năm trước cách đây
mục cha
commit
79d592c94f
2 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 1 0
      doc/CHANGES.txt
  2. 5 0
      typer.ml

+ 1 - 0
doc/CHANGES.txt

@@ -5,6 +5,7 @@
 	fixed stack overflow in typedefs
 	added haxe.Timer.queue, removed delayedArg (use callback instead)
 	fixed haxe.remoting.SocketConnection (msg invertions might occur)
+	add uniqueness check for switch constants
 
 2007-03-06: 1.12
 	added flash lite support with -D flash_lite

+ 5 - 0
typer.ml

@@ -1472,9 +1472,14 @@ and type_switch ctx e cases def need_val p =
 	let t = !t in
 	match !enum with
 	| None ->
+		let consts = Hashtbl.create 0 in
 		let exprs (el,e) =
 			List.map (fun c ->
 				match c with
+				| CExpr (({ eexpr = TConst c }) as e) ->
+					if Hashtbl.mem consts c then error "Duplicate constant in swtich" e.epos;
+					Hashtbl.add consts c true;
+					e
 				| CExpr c -> c
 				| _ -> assert false
 			) el , e