Browse Source

lose lose bool-return restrictions for `is` overloads

Dan Korostelev 4 years ago
parent
commit
beae5e7dd4
2 changed files with 3 additions and 7 deletions
  1. 2 1
      src/typing/operators.ml
  2. 1 6
      src/typing/typeloadFields.ml

+ 2 - 1
src/typing/operators.ml

@@ -936,7 +936,8 @@ let type_is ctx e t p_t p =
 				(* abstract with @:op(v is T) -> generate static call *)
 				(* abstract with @:op(v is T) -> generate static call *)
 				let e_method = Texpr.Builder.make_static_field c cf (mk_zero_range_pos p) in
 				let e_method = Texpr.Builder.make_static_field c cf (mk_zero_range_pos p) in
 				let e = AbstractCast.cast_or_unify ctx arg_t e p in
 				let e = AbstractCast.cast_or_unify ctx arg_t e p in
-				mk (TCall (e_method, [e])) ctx.com.basic.tbool p
+				let t_ret = match cf.cf_type with TFun (_, t) -> t | _ -> die ~p "unexpected @:op(v is T) type" __LOC__ in
+				mk (TCall (e_method, [e])) t_ret p
 
 
 			| _ ->
 			| _ ->
 				(* everything else - generate Std.isOfType(v, T) *)
 				(* everything else - generate Std.isOfType(v, T) *)

+ 1 - 6
src/typing/typeloadFields.ml

@@ -1075,14 +1075,9 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					if fctx.is_abstract_member then error "`is` overloads must be static" cf.cf_pos;
 					if fctx.is_abstract_member then error "`is` overloads must be static" cf.cf_pos;
 					begin match follow t with
 					begin match follow t with
 						| TFun ([(_,false,t)], tr) ->
 						| TFun ([(_,false,t)], tr) ->
-							delay ctx PCheckConstraint (fun () ->
-								match follow tr with
-								| TAbstract ({ a_path = [],"Bool" },_) -> ()
-								| _ -> error "`is` overload must return Bool" cf.cf_pos
-							);
 							a.a_is <- Some (t,cf);
 							a.a_is <- Some (t,cf);
 						| _ ->
 						| _ ->
-							error ("`is` overload must be a function that takes a single non-optional argument and returns Bool") cf.cf_pos
+							error ("`is` overload must be a function that takes a single non-optional argument") cf.cf_pos
 					end
 					end
 				| (Meta.Op,[EBinop(op,_,_),_],_) :: _ ->
 				| (Meta.Op,[EBinop(op,_,_),_],_) :: _ ->
 					if fctx.is_macro then error (cf.cf_name ^ ": Macro operator functions are not supported") p;
 					if fctx.is_macro then error (cf.cf_name ^ ": Macro operator functions are not supported") p;