Browse Source

disallow initialization of non-physical fields (closes #1958)

Simon Krajewski 12 years ago
parent
commit
5e9d48913a
2 changed files with 5 additions and 2 deletions
  1. 2 2
      tests/unit/TestDCE.hx
  2. 3 0
      typeload.ml

+ 2 - 2
tests/unit/TestDCE.hx

@@ -20,14 +20,14 @@ class DCEClass {
 	// unused statics
 	static function staticUnused() { }
 	static var staticVarUnused = "bar";
-	static var staticPropUnused(get, set):Int = 1;
+	static var staticPropUnused(get, set):Int;
 	static function get_staticPropUnused() return 0;
 	static function set_staticPropUnused(i:Int) return 0;
 	
 	// unused members
 	function memberUnused() { }
 	var memberVarUnused = 1;
-	var memberPropUnused(get, set):Int = 1;
+	var memberPropUnused(get, set):Int;
 	function get_memberPropUnused() return 0;
 	function set_memberPropUnused(i:Int) return 0;
 	

+ 3 - 0
typeload.ml

@@ -1523,6 +1523,9 @@ let init_class ctx c p context_init herits fields =
 							| Some e -> e
 							| None -> display_error ctx "Extern variable initialization must be a constant value" p; e
 						end
+					| 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) ->
 						let e = match Optimizer.make_constant_expression ctx e with Some e -> check_cast e | None -> display_error ctx "Variable initialization must be a constant value" p; e in
 						e