Browse Source

force constant value for inline initialization (closes #2363)

Simon Krajewski 11 years ago
parent
commit
d9d020be84
2 changed files with 11 additions and 8 deletions
  1. 2 2
      std/haxe/Int32.hx
  2. 9 6
      typeload.ml

+ 2 - 2
std/haxe/Int32.hx

@@ -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;
@@ -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 {

+ 9 - 6
typeload.ml

@@ -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