浏览代码

[typer] require type-hints for extern field modifier too

see #10605
Simon Krajewski 3 年之前
父节点
当前提交
d4ada56211
共有 5 个文件被更改,包括 27 次插入23 次删除
  1. 0 15
      src/typing/functionArguments.ml
  2. 21 2
      src/typing/typeloadFields.ml
  3. 1 1
      std/cpp/Lib.hx
  4. 1 1
      std/cpp/NativeXml.hx
  5. 4 4
      std/eval/_std/sys/net/Host.hx

+ 0 - 15
src/typing/functionArguments.ml

@@ -4,21 +4,6 @@ open Type
 open Typecore
 open Error
 
-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) ->
-		display_error ctx "Type required for extern classes and interfaces" p;
-		t_dynamic
-	| 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
-
 let type_function_arg ctx t e opt p =
 	(* TODO https://github.com/HaxeFoundation/haxe/issues/8461 *)
 	(* delay ctx PTypeField (fun() ->

+ 21 - 2
src/typing/typeloadFields.ml

@@ -1181,6 +1181,25 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 		| _ ->
 			()
 
+let type_opt (ctx,cctx,fctx) p t =
+	let c = cctx.tclass in
+	let is_truly_extern =
+		(has_class_flag c CExtern || fctx.is_extern)
+		&& not fctx.is_inline (* if it's inline, we can infer the type from the expression *)
+	in
+	match t with
+	| None when is_truly_extern || (has_class_flag c CInterface) ->
+		display_error ctx "Type required for extern classes and interfaces" p;
+		t_dynamic
+	| None when cctx.is_core_api ->
+		display_error ctx "Type required for core api classes" p;
+		t_dynamic
+	| None when fctx.is_abstract ->
+		display_error ctx "Type required for abstract functions" p;
+		t_dynamic
+	| _ ->
+		Typeload.load_type_hint ctx p t
+
 let create_method (ctx,cctx,fctx) c f fd p =
 	let name = fst f.cff_name in
 	let params = TypeloadFunction.type_function_params ctx fd name p in
@@ -1289,7 +1308,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 		ctx.t.tvoid
 	else begin
 		let def () =
-			FunctionArguments.type_opt ctx cctx.is_core_api fctx.is_abstract p fd.f_type
+			type_opt (ctx,cctx,fctx) p fd.f_type
 		in
 		maybe_use_property_type fd.f_type (fun () -> match Lazy.force mk with MKGetter | MKSetter -> true | _ -> false) def
 	end in
@@ -1302,7 +1321,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	let is_extern = fctx.is_extern || has_class_flag ctx.curclass CExtern in
 	let type_arg i opt cto p =
 		let def () =
-			FunctionArguments.type_opt ctx cctx.is_core_api fctx.is_abstract p cto
+			type_opt (ctx,cctx,fctx) p cto
 		in
 		if i = 0 then maybe_use_property_type cto (fun () -> match Lazy.force mk with MKSetter -> true | _ -> false) def else def()
 	in

+ 1 - 1
std/cpp/Lib.hx

@@ -79,7 +79,7 @@ class Lib {
 	}
 
 	@:noDebug @:native("HX_STACK_DO_RETHROW")
-	extern static function do_rethrow(inExp:Dynamic);
+	extern static function do_rethrow(inExp:Dynamic):Void;
 
 	@:noDebug #if (!cppia) inline #end
 	public static function rethrow(inExp:Dynamic) {

+ 1 - 1
std/cpp/NativeXml.hx

@@ -221,7 +221,7 @@ class Xml {
 	function new():Void {}
 
 	@:native("parse_xml")
-	extern static function parse_xml(str:String, state:NativeXmlState);
+	extern static function parse_xml(str:String, state:NativeXmlState):String;
 
 	public static function parse(str:String):Xml {
 		var x = new Xml();

+ 4 - 4
std/eval/_std/sys/net/Host.hx

@@ -43,11 +43,11 @@ class Host {
 		this.ip = ip;
 	}
 
-	extern static public function localhost();
+	extern static public function localhost():String;
 
-	extern static function hostReverse(ip:Int);
+	extern static function hostReverse(ip:Int):String;
 
-	extern static function hostToString(ip:Int);
+	extern static function hostToString(ip:Int):String;
 
-	extern static function resolve(name:String);
+	extern static function resolve(name:String):Int;
 }