瀏覽代碼

only check for "this" in constant initialization after optimizing the expression (allow for type inference with discarded branches)

Nicolas Cannasse 7 年之前
父節點
當前提交
577f0c95c7
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      src/typing/typeload.ml

+ 7 - 7
src/typing/typeload.ml

@@ -2252,6 +2252,11 @@ module ClassInitializer = struct
 						let e = if ctx.com.display.dms_display && ctx.com.display.dms_error_policy <> EPCollect then
 							e
 						else begin
+							let e = Optimizer.reduce_loop ctx (maybe_run_analyzer e) in
+							let e = (match Optimizer.make_constant_expression ctx e with
+								| Some e -> e
+								| None -> e
+							) in
 							let rec check_this e = match e.eexpr with
 								| TConst TThis ->
 									display_error ctx "Cannot access this or other member field in variable initialization" e.epos;
@@ -2262,13 +2267,8 @@ module ClassInitializer = struct
 								| _ ->
 								Type.iter check_this e
 							in
-							try
-								check_this e;
-								match Optimizer.make_constant_expression ctx (maybe_run_analyzer e) with
-								| Some e -> e
-								| None -> e
-							with Exit ->
-								e
+							(try check_this e with Exit -> ());
+							e
 						end in
 						e
 					| Var v when v.v_read = AccInline ->