Skip to content

Commit

Permalink
force constant value for inline initialization (closes HaxeFoundation…
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Nov 23, 2013
1 parent d3d9ee4 commit d9d020b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions std/haxe/Int32.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
Int32 provides a 32-bit integer with consistent overflow behavior across
all platforms.
all platforms.
**/
abstract Int32(Int) from Int to Int {
@:op(-A) public function negate():Int32;
Expand Down Expand Up @@ -149,7 +149,7 @@ abstract Int32(Int) from Int to Int {
return this;

#if php
static inline var extraBits : Int = untyped __php__("PHP_INT_SIZE") * 8 - 32;
static var extraBits : Int = untyped __php__("PHP_INT_SIZE") * 8 - 32;
#end

inline static function clamp( x : Int ) : Int {
Expand Down
15 changes: 9 additions & 6 deletions typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit d9d020b

Please sign in to comment.