浏览代码

constants uniqueness in switch

Nicolas Cannasse 18 年之前
父节点
当前提交
79d592c94f
共有 2 个文件被更改,包括 6 次插入0 次删除
  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
 	fixed stack overflow in typedefs
 	added haxe.Timer.queue, removed delayedArg (use callback instead)
 	added haxe.Timer.queue, removed delayedArg (use callback instead)
 	fixed haxe.remoting.SocketConnection (msg invertions might occur)
 	fixed haxe.remoting.SocketConnection (msg invertions might occur)
+	add uniqueness check for switch constants
 
 
 2007-03-06: 1.12
 2007-03-06: 1.12
 	added flash lite support with -D flash_lite
 	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
 	let t = !t in
 	match !enum with
 	match !enum with
 	| None ->
 	| None ->
+		let consts = Hashtbl.create 0 in
 		let exprs (el,e) =
 		let exprs (el,e) =
 			List.map (fun c ->
 			List.map (fun c ->
 				match c with
 				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
 				| CExpr c -> c
 				| _ -> assert false
 				| _ -> assert false
 			) el , e
 			) el , e