|
@@ -1543,6 +1543,10 @@ let init_class ctx c p context_init herits fields =
|
|
|
context_init();
|
|
|
if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ cf.cf_name);
|
|
|
let e = type_var_field ctx t e stat p in
|
|
|
+ let require_constant_expression e msg = match Optimizer.make_constant_expression ctx e with
|
|
|
+ | Some e -> e
|
|
|
+ | None -> display_error ctx msg p; e
|
|
|
+ in
|
|
|
let e = (match cf.cf_kind with
|
|
|
| Var v when c.cl_extern || Meta.has Meta.Extern cf.cf_meta ->
|
|
|
if not stat then begin
|
|
@@ -1551,15 +1555,11 @@ let init_class ctx c p context_init herits fields =
|
|
|
end else if v.v_read <> AccInline then begin
|
|
|
display_error ctx "Extern non-inline variables may not be initialized" p;
|
|
|
e
|
|
|
- end else begin
|
|
|
- match Optimizer.make_constant_expression ctx e with
|
|
|
- | Some e -> e
|
|
|
- | None -> display_error ctx "Extern variable initialization must be a constant value" p; e
|
|
|
- end
|
|
|
+ end else require_constant_expression e "Extern variable initialization must be a constant value"
|
|
|
| Var v when is_extern_field cf ->
|
|
|
(* disallow initialization of non-physical fields (issue #1958) *)
|
|
|
display_error ctx "This field cannot be initialized because it is not a real variable" p; e
|
|
|
- | Var v when not stat || (v.v_read = AccInline) ->
|
|
|
+ | Var v when not stat ->
|
|
|
let e = match Optimizer.make_constant_expression ctx e with
|
|
|
| Some e -> e
|
|
|
| None ->
|
|
@@ -1573,6 +1573,9 @@ let init_class ctx c p context_init herits fields =
|
|
|
e
|
|
|
in
|
|
|
check_cast e
|
|
|
+ | Var v when v.v_read = AccInline ->
|
|
|
+ let e = require_constant_expression e "Inline variable initialization must be a constant value" in
|
|
|
+ check_cast e
|
|
|
| _ ->
|
|
|
e
|
|
|
) in
|