Browse Source

disallow Void in class/structure fields and enum constructors (fixed issue #1289)

Simon Krajewski 13 years ago
parent
commit
ccdca0be62
6 changed files with 9 additions and 4 deletions
  1. 2 1
      codegen.ml
  2. 1 1
      std/haxe/io/BytesBuffer.hx
  3. 1 1
      std/neko/net/Poll.hx
  4. 1 1
      std/neko/vm/Lock.hx
  5. 3 0
      typeload.ml
  6. 1 0
      typer.ml

+ 2 - 1
codegen.ml

@@ -657,10 +657,11 @@ let add_rtti ctx t =
 	| _ ->
 	| _ ->
 		()
 		()
 
 
-(* Removes extern and macro fields *)
+(* Removes extern and macro fields, also checks for Void fields *)
 let remove_extern_fields ctx t = match t with
 let remove_extern_fields ctx t = match t with
 	| TClassDecl c ->
 	| TClassDecl c ->
 		let do_remove f =
 		let do_remove f =
+			(match follow f.cf_type with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed" f.cf_pos | _ -> ());
 			(not ctx.in_macro && f.cf_kind = Method MethMacro) || has_meta ":extern" f.cf_meta || has_meta ":generic" f.cf_meta
 			(not ctx.in_macro && f.cf_kind = Method MethMacro) || has_meta ":extern" f.cf_meta || has_meta ":generic" f.cf_meta
 		in
 		in
 		if not (Common.defined ctx.com Define.DocGen) then begin
 		if not (Common.defined ctx.com Define.DocGen) then begin

+ 1 - 1
std/haxe/io/BytesBuffer.hx

@@ -24,7 +24,7 @@ package haxe.io;
 class BytesBuffer {
 class BytesBuffer {
 
 
 	#if neko
 	#if neko
-	var b : Void; // neko string buffer
+	var b : Dynamic; // neko string buffer
 	#elseif flash9
 	#elseif flash9
 	var b : flash.utils.ByteArray;
 	var b : flash.utils.ByteArray;
 	#elseif php
 	#elseif php

+ 1 - 1
std/neko/net/Poll.hx

@@ -24,7 +24,7 @@ import sys.net.Socket;
 
 
 class Poll {
 class Poll {
 
 
-	var d : Void;
+	var d : Dynamic;
 	public var readIndexes : ArrayAccess<Int>;
 	public var readIndexes : ArrayAccess<Int>;
 	public var writeIndexes : ArrayAccess<Int>;
 	public var writeIndexes : ArrayAccess<Int>;
 
 

+ 1 - 1
std/neko/vm/Lock.hx

@@ -22,7 +22,7 @@
 package neko.vm;
 package neko.vm;
 
 
 class Lock {
 class Lock {
-	var l : Void;
+	var l : Dynamic;
 	public function new() {
 	public function new() {
 		l = lock_create();
 		l = lock_create();
 	}
 	}

+ 3 - 0
typeload.ml

@@ -369,6 +369,8 @@ and load_complex_type ctx p t =
 				| AStatic | AOverride | AInline | ADynamic -> error ("Invalid access " ^ Ast.s_access a) p
 				| AStatic | AOverride | AInline | ADynamic -> error ("Invalid access " ^ Ast.s_access a) p
 			) f.cff_access;
 			) f.cff_access;
 			let t , access = (match f.cff_kind with
 			let t , access = (match f.cff_kind with
+				| 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) ->
 				| FVar (t, e) ->
 					no_expr e;
 					no_expr e;
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }
@@ -1749,6 +1751,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 				| l ->
 				| l ->
 					let pnames = ref PMap.empty in
 					let pnames = ref PMap.empty in
 					TFun (List.map (fun (s,opt,t) ->
 					TFun (List.map (fun (s,opt,t) ->
+						(match t with CTPath({tpackage=[];tname="Void"}) -> error "Arguments of type Void are not allowed in enum constructors" c.ec_pos | _ -> ());
 						if PMap.mem s (!pnames) then error ("Duplicate parameter '" ^ s ^ "' in enum constructor " ^ c.ec_name) p;
 						if PMap.mem s (!pnames) then error ("Duplicate parameter '" ^ s ^ "' in enum constructor " ^ c.ec_name) p;
 						pnames := PMap.add s () (!pnames);
 						pnames := PMap.add s () (!pnames);
 						s, opt, load_type_opt ~opt ctx p (Some t)
 						s, opt, load_type_opt ~opt ctx p (Some t)

+ 1 - 0
typer.ml

@@ -2086,6 +2086,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 			let f,add = object_field f in
 			let f,add = object_field f in
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
 			let e = type_expr ctx e in
 			let e = type_expr ctx e 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 e.epos in
 			let cf = mk_field f e.etype e.epos in
 			((f,e) :: l, if add then PMap.add f cf acc else acc)
 			((f,e) :: l, if add then PMap.add f cf acc else acc)
 		in
 		in