2
0
Dan Korostelev 4 жил өмнө
parent
commit
0b70d9d469

+ 0 - 12
src/filters/filters.ml

@@ -609,17 +609,6 @@ let check_remove_metadata ctx t = match t with
 	| _ ->
 		()
 
-(* Checks for Void class fields *)
-let check_void_field ctx t = match t with
-	| TClassDecl c ->
-		let check f =
-			match follow f.cf_type with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed" f.cf_pos | _ -> ();
-		in
-		List.iter check c.cl_ordered_fields;
-		List.iter check c.cl_ordered_statics;
-	| _ ->
-		()
-
 (* Interfaces have no 'super', but can extend many other interfaces.
    This makes the first extended (implemented) interface the super for efficiency reasons (you can get one for 'free')
    and leaves the remaining ones as 'implemented' *)
@@ -842,7 +831,6 @@ let run com tctx main =
 		add_rtti;
 		(match com.platform with | Java | Cs -> (fun _ _ -> ()) | _ -> add_field_inits locals);
 		(match com.platform with Hl -> (fun _ _ -> ()) | _ -> add_meta_field);
-		check_void_field;
 		(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ _ -> ()) );
 		commit_features;
 		(if com.config.pf_reserved_type_paths <> [] then check_reserved_type_paths else (fun _ _ -> ()));

+ 0 - 2
src/typing/typeload.ml

@@ -552,8 +552,6 @@ and load_complex_type' ctx allow_display (t,p) =
 					no_expr e;
 					let t = (match t with None -> error "Type required for structure property" p | Some t -> t) in
 					load_complex_type ctx allow_display t, Var { v_read = AccNormal; v_write = AccNever }
-				| FVar (Some (CTPath({tpackage=[];tname="Void"}),_), _)  | FProp (_,_,Some (CTPath({tpackage=[];tname="Void"}),_),_) ->
-					error "Fields of type Void are not allowed in structures" p
 				| FVar (t, e) ->
 					no_expr e;
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }

+ 0 - 1
src/typing/typer.ml

@@ -833,7 +833,6 @@ and type_object_decl ctx fl with_type p =
 			let is_valid = Lexer.is_valid_identifier f in
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
 			let e = type_expr ctx e (WithType.named_structure_field f) in
-			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			let cf = mk_field f e.etype (punion pf e.epos) pf in
 			if ctx.in_display && DisplayPosition.display_position#enclosed_in pf then DisplayEmitter.display_field ctx Unknown CFSMember cf pf;
 			(((f,pf,qs),e) :: l, if is_valid then begin

+ 24 - 0
tests/unit/src/unit/TestVoid.hx

@@ -42,6 +42,25 @@ class TestVoid extends Test {
 		HelperMacros.typedAs(v, (null : Void));
 		eq(Void, v);
 	}
+
+	function testField() {
+		var c = new C();
+		eq(Void, c.field);
+		c.field = Void;
+		eq(Void, c.field);
+	}
+
+	function testStructField() {
+		var c = {field: Void}
+		eq(Void, c.field);
+		c.field = Void;
+		eq(Void, c.field);
+
+		var c:{field:Void} = {field: Void}
+		eq(Void, c.field);
+		c.field = Void;
+		eq(Void, c.field);
+	}
 }
 
 private function voidReturn() {}
@@ -68,3 +87,8 @@ private class Signal<T> {
 		return payload;
 	}
 }
+
+private class C {
+	public var field:Void;
+	public function new() {}
+}