2
0
Simon Krajewski 4 жил өмнө
parent
commit
95407030c9

+ 7 - 4
src/core/error.ml

@@ -148,6 +148,9 @@ module BetterErrors = struct
 		) l;
 		root_acc
 
+	let maybe_coro coro s =
+		if coro then Printf.sprintf "Coroutine<%s>" s else s
+
 	(* non-recursive s_type *)
 	let rec s_type ctx t =
 		match t with
@@ -165,9 +168,9 @@ module BetterErrors = struct
 			s_type_path t.t_path ^ s_type_params ctx tl
 		| TAbstract (a,tl) ->
 			s_type_path a.a_path ^ s_type_params ctx tl
-		| TFun ([],_,corotodo) ->
-			"() -> ..."
-		| TFun (l,t,corotodo) ->
+		| TFun ([],_,coro) ->
+			maybe_coro coro "() -> ..."
+		| TFun (l,t,coro) ->
 			let args = match l with
 				| [] -> "()"
 				| ["",b,t] -> ("...")
@@ -177,7 +180,7 @@ module BetterErrors = struct
 					) l) in
 					"(" ^ args ^ ")"
 			in
-			Printf.sprintf "%s -> ..." args
+			maybe_coro coro (Printf.sprintf "%s -> ..." args)
 		| TAnon a ->
 			begin
 				match !(a.a_status) with

+ 6 - 2
src/core/tOther.ml

@@ -34,8 +34,12 @@ module TExprToExpr = struct
 			if (snd t.t_path).[0] = '#' then convert_type (follow tf) else tpath t.t_path t.t_module.m_path (List.map tparam pl)
 		| TAbstract (a,pl) ->
 			tpath a.a_path a.a_module.m_path (List.map tparam pl)
-		| TFun (args,ret,corotodo) ->
-			CTFunction (List.map (fun (_,_,t) -> convert_type' t) args, (convert_type' ret))
+		| TFun (args,ret,coro) ->
+			let ct_fun = CTFunction (List.map (fun (_,_,t) -> convert_type' t) args, (convert_type' ret)) in
+			if coro then
+				tpath ([],"Coroutine") ([],"Coroutine") [TPType (ct_fun,null_pos)]
+			else
+				ct_fun
 		| TAnon a ->
 			begin match !(a.a_status) with
 			| Statics c -> tpath ([],"Class") ([],"Class") [TPType (tpath c.cl_path c.cl_path [],null_pos)]

+ 8 - 8
src/typing/typeloadFields.ml

@@ -1024,7 +1024,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 						(* the return type of a from-function must be the abstract, not the underlying type *)
 						if not fctx.is_macro then (try type_eq EqStrict ret ta with Unify_error l -> error (error_msg (Unify l)) p);
 						match t with
-							| TFun([_,_,t],_,corotodo) -> t
+							| TFun([_,_,t],_,_) -> t
 							| _ -> error (cf.cf_name ^ ": @:from cast functions must accept exactly one argument") p
 					) "@:from" in
 					a.a_from_field <- (TLazy r,cf) :: a.a_from_field;
@@ -1033,12 +1033,12 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					(match cf.cf_kind, cf.cf_type with
 					| Var _, _ ->
 						error "@:to meta should be used on methods" p
-					| Method _, TFun(args, _, corotodo) when not fctx.is_abstract_member && List.length args <> 1 ->
+					| Method _, TFun(args, _, _) when not fctx.is_abstract_member && List.length args <> 1 ->
 						if not (Meta.has Meta.MultiType a.a_meta) then (* TODO: get rid of this check once multitype is removed *)
-						error ("static @:to method should have one argument") p
-					| Method _, TFun(args, _, corotodo) when fctx.is_abstract_member && List.length args <> 1 ->
+							error ("static @:to method should have one argument") p
+					| Method _, TFun(args, _, _) when fctx.is_abstract_member && List.length args <> 1 ->
 						if not (Meta.has Meta.MultiType a.a_meta) then (* TODO: get rid of this check once multitype is removed *)
-						error "@:to method should have no arguments" p
+							error "@:to method should have no arguments" p
 					| _ -> ()
 					);
 					(* TODO: this doesn't seem quite right... *)
@@ -1082,7 +1082,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					if fctx.is_macro then error (cf.cf_name ^ ": Macro operator functions are not supported") p;
 					let targ = if fctx.is_abstract_member then tthis else ta in
 					let left_eq,right_eq = match follow t with
-						| TFun([(_,_,t1);(_,_,t2)],_,corotodo) ->
+						| TFun([(_,_,t1);(_,_,t2)],_,_) ->
 							type_iseq targ t1,type_iseq targ t2
 						| _ ->
 							if fctx.is_abstract_member then
@@ -1117,11 +1117,11 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 						end
 					in
 					begin match follow t with
-						| TFun([(_,_,t1);(_,_,t2)],_,corotodo) ->
+						| TFun([(_,_,t1);(_,_,t2)],_,_) ->
 							if a.a_read <> None then error "Multiple resolve-read methods are not supported" cf.cf_pos;
 							check_fun t1 t2;
 							a.a_read <- Some cf;
-						| TFun([(_,_,t1);(_,_,t2);(_,_,t3)],_,corotodo) ->
+						| TFun([(_,_,t1);(_,_,t2);(_,_,t3)],_,_) ->
 							if a.a_write <> None then error "Multiple resolve-write methods are not supported" cf.cf_pos;
 							check_fun t1 t2;
 							a.a_write <- Some cf;

+ 5 - 3
src/typing/typer.ml

@@ -203,8 +203,10 @@ let rec unify_min_raise ctx (el:texpr list) : t =
 					raise Exit
 			in
 			let arity = Array.length args in
+			let is_coro = ref false in
 			let rets = List.map (fun e -> match follow e.etype with
-				| TFun(tl,tr,_) ->
+				| TFun(tl,tr,coro) ->
+					is_coro := coro; (* no need for special checks, this will only unify if everything either is or isn't a coro anyway *)
 					let ta = Array.of_list tl in
 					if Array.length ta <> arity then raise Exit;
 					for i = 0 to arity - 1 do
@@ -226,7 +228,7 @@ let rec unify_min_raise ctx (el:texpr list) : t =
 			| UnifyMinError(l,index) ->
 				raise Exit
 			in
-			TFun(Array.to_list args,tr,false (* corotodo *))
+			TFun(Array.to_list args,tr,!is_coro)
 		with Exit ->
 			(* Second pass: Get all base types (interfaces, super classes and their interfaces) of most general type.
 			   Then for each additional type filter all types that do not unify. *)
@@ -1189,7 +1191,7 @@ and type_local_function ctx kind f with_type p want_coroutine =
 	| WithType.WithType(t,_) ->
 		let rec loop t =
 			(match follow t with
-			| TFun (args2,tr,corotodo) when List.length args2 = List.length targs ->
+			| TFun (args2,tr,_) when List.length args2 = List.length targs ->
 				List.iter2 (fun (_,_,t1) (_,_,t2) ->
 					match follow t1 with
 					| TMono _ -> unify ctx t2 t1 p