Browse Source

require argument types and return type for abstract functions (closes #9984)

Aleksandr Kuzmenko 4 years ago
parent
commit
27bb6a4664
2 changed files with 6 additions and 3 deletions
  1. 4 1
      src/typing/functionArguments.ml
  2. 2 2
      src/typing/typeloadFields.ml

+ 4 - 1
src/typing/functionArguments.ml

@@ -4,7 +4,7 @@ open Type
 open Typecore
 open Error
 
-let type_opt ctx is_core_api p t =
+let type_opt ctx is_core_api is_abstract_method p t =
 	let c = ctx.curclass in
 	match t with
 	| None when (has_class_flag c CExtern) || (has_class_flag c CInterface) ->
@@ -13,6 +13,9 @@ let type_opt ctx is_core_api p t =
 	| None when is_core_api ->
 		display_error ctx "Type required for core api classes" p;
 		t_dynamic
+	| None when is_abstract_method ->
+		display_error ctx "Type required for abstract functions" p;
+		t_dynamic
 	| _ ->
 		Typeload.load_type_hint ctx p t
 

+ 2 - 2
src/typing/typeloadFields.ml

@@ -1209,7 +1209,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 
 	ctx.type_params <- if fctx.is_static && not fctx.is_abstract_member then params else params @ ctx.type_params;
 	(* TODO is_lib: avoid forcing the return type to be typed *)
-	let ret = if fctx.field_kind = FKConstructor then ctx.t.tvoid else FunctionArguments.type_opt ctx cctx.is_core_api p fd.f_type in
+	let ret = if fctx.field_kind = FKConstructor then ctx.t.tvoid else FunctionArguments.type_opt ctx cctx.is_core_api fctx.is_abstract p fd.f_type in
 	let abstract_this = match cctx.abstract with
 		| Some a when fctx.is_abstract_member && fst f.cff_name <> "_new" (* TODO: this sucks *) && not fctx.is_macro ->
 			Some a.a_this
@@ -1217,7 +1217,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 			None
 	in
 	let is_extern = fctx.is_extern || has_class_flag ctx.curclass CExtern in
-	let type_arg opt t p = FunctionArguments.type_opt ctx cctx.is_core_api p t in
+	let type_arg opt t p = FunctionArguments.type_opt ctx cctx.is_core_api fctx.is_abstract p t in
 	let args = new FunctionArguments.function_arguments ctx type_arg is_extern fctx.is_display_field abstract_this fd.f_args in
 	let t = TFun (args#for_type,ret) in
 	let cf = {