Selaa lähdekoodia

also disallow Void for local vars (#6201)

Aleksandr Kuzmenko 6 vuotta sitten
vanhempi
commit
51bdcb8da1

+ 2 - 3
src/typing/typeloadFunction.ml

@@ -30,9 +30,8 @@ open Error
 
 let type_function_arg ctx t e opt p =
 	delay ctx PTypeField (fun() ->
-		match follow t with
-		| TAbstract ({a_path = [],"Void"},_) -> error "Arguments of type Void are not allowed" p
-		| _ -> ()
+		if ExtType.is_void (follow t) then
+			error "Arguments of type Void are not allowed" p
 	);
 	if opt then
 		let e = (match e with None -> Some (EConst (Ident "null"),null_pos) | _ -> e) in

+ 8 - 0
src/typing/typer.ml

@@ -1458,6 +1458,14 @@ and type_vars ctx vl p =
 				check_error ctx e p;
 				add_local ctx VGenerated v t_dynamic pv, None (* TODO: What to do with this... *)
 	) vl in
+	delay ctx PTypeField (fun() ->
+		List.iter
+			(fun (v,_) ->
+				if ExtType.is_void (follow v.v_type) then
+					error "Variables of type Void are not allowed" v.v_pos
+			)
+			vl
+	);
 	match vl with
 	| [v,eo] ->
 		mk (TVar (v,eo)) ctx.t.tvoid p

+ 1 - 1
tests/misc/projects/Issue6201/Main.hx → tests/misc/projects/Issue6201/Main1.hx

@@ -1,4 +1,4 @@
-class Main {
+class Main1 {
 	static function method(param:Void = null) {}
 
 	public static function main() {}

+ 5 - 0
tests/misc/projects/Issue6201/Main2.hx

@@ -0,0 +1,5 @@
+class Main2 {
+	public static function main() {
+		var v:Void;
+	}
+}

+ 0 - 1
tests/misc/projects/Issue6201/compile-fail.hxml

@@ -1 +0,0 @@
--main Main

+ 0 - 1
tests/misc/projects/Issue6201/compile-fail.hxml.stderr

@@ -1 +0,0 @@
-Main.hx:2: characters 25-30 : Arguments of type Void are not allowed

+ 1 - 0
tests/misc/projects/Issue6201/compile1-fail.hxml

@@ -0,0 +1 @@
+-main Main1

+ 1 - 0
tests/misc/projects/Issue6201/compile1-fail.hxml.stderr

@@ -0,0 +1 @@
+Main1.hx:2: characters 25-30 : Arguments of type Void are not allowed

+ 1 - 0
tests/misc/projects/Issue6201/compile2-fail.hxml

@@ -0,0 +1 @@
+-main Main2

+ 1 - 0
tests/misc/projects/Issue6201/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+Main2.hx:3: characters 7-8 : Variables of type Void are not allowed