浏览代码

be again a bit more liberal on the things we allow in inline var

Nicolas Cannasse 13 年之前
父节点
当前提交
5bed8e3a09
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      typeload.ml

+ 8 - 4
typeload.ml

@@ -923,10 +923,14 @@ let init_class ctx c p herits fields =
 							let e = type_static_var ctx t e p in
 							let e = type_static_var ctx t e p in
 							let e = (if inline then 
 							let e = (if inline then 
 								let e = ctx.g.do_optimize ctx e in
 								let e = ctx.g.do_optimize ctx e in
-								(match e.eexpr with
-								| TConst _ -> ()
-								| TBinop ((OpAdd|OpSub|OpMult|OpDiv|OpMod),{ eexpr = TConst (TInt _|TString _|TFloat _) },{ eexpr = TConst (TInt _|TString _|TFloat _) }) -> ()
-								| _ -> display_error ctx "Inline variable must be a constant value" p);
+								let rec is_const e =
+									match e.eexpr with
+									| TConst _ -> true
+									| TBinop ((OpAdd|OpSub|OpMult|OpDiv|OpMod),e1,e2) -> is_const e1 && is_const e2
+									| TParenthesis e -> is_const e
+									| _ -> false
+								in
+								if not (is_const e) then display_error ctx "Inline variable must be a constant value" p;
 								e
 								e
 							else e) in
 							else e) in
 							cf.cf_expr <- Some e;
 							cf.cf_expr <- Some e;