Browse Source

this will be terrible

Simon Krajewski 9 months ago
parent
commit
68447c25f1
4 changed files with 20 additions and 15 deletions
  1. 5 0
      src-json/warning.json
  2. 7 8
      src/typing/typeload.ml
  3. 1 0
      std/jvm/_std/Reflect.hx
  4. 7 7
      std/jvm/_std/String.hx

+ 5 - 0
src-json/warning.json

@@ -124,6 +124,11 @@
 		"parent": "WTyper",
 		"enabled": false
 	},
+	{
+		"name": "WMetaOverload",
+		"doc": "Deprecation of `@:overload(function ())` syntax",
+		"parent": "WDeprecated"
+	},
 	{
 		"name": "WHxb",
 		"doc": "Hxb (either --hxb output or haxe compiler cache) related warnings"

+ 7 - 8
src/typing/typeload.ml

@@ -641,24 +641,23 @@ and init_meta_overloads ctx co cf =
 		| ((Meta.Overload | Meta.Value),_,_) -> false
 		| _ -> true
 	in
+	let warning_options = match co with
+		| Some c ->
+			Warning.from_meta c.cl_meta
+		| None ->
+			[]
+	in
 	let cf_meta = List.filter filter_meta cf.cf_meta in
 	cf.cf_meta <- List.filter (fun m ->
 		match m with
 		| (Meta.Overload,[(EFunction (kind,f),p)],_)  ->
+			module_warning ctx.com ctx.m.curmod WMetaOverload (Warning.from_meta cf.cf_meta @ warning_options) "`@:overload(function())` syntax is deprecated in favor of individual `@:overload function` declarations" p;
 			(match kind with FKNamed _ -> raise_typing_error "Function name must not be part of @:overload" p | _ -> ());
 			(match f.f_expr with Some (EBlock [], _) -> () | _ -> raise_typing_error "Overload must only declare an empty method body {}" p);
 			(match cf.cf_kind with
 				| Method MethInline -> raise_typing_error "Cannot @:overload inline function" p
 				| _ -> ());
 			let old = ctx.type_params in
-			begin match cf.cf_params with
-				| [] ->
-					()
-				| l ->
-					ctx.type_params <- List.filter (fun ttp ->
-						ttp.ttp_host <> TPHMethod
-					) ctx.type_params
-			end;
 			let params : type_params = (!type_function_params_ref) ctx f TPHMethod cf.cf_name p in
 			ctx.type_params <- params @ ctx.type_params;
 			let topt mode = function None -> raise_typing_error "Explicit type required" p | Some t -> load_complex_type ctx true mode t in

+ 1 - 0
std/jvm/_std/Reflect.hx

@@ -207,6 +207,7 @@ class Reflect {
 	}
 
 	@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
+	@:haxe.warning("-WMetaOverload")
 	public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
 		return new jvm.Closure.VarArgs((cast f : jvm.Function));
 	}

+ 7 - 7
std/jvm/_std/String.hx

@@ -24,11 +24,11 @@
 extern class String implements java.lang.CharSequence {
 	var length(default, null):Int;
 
-	@:overload(function(b:haxe.io.BytesData, offset:Int, length:Int, charsetName:String):Void {})
-	@:overload(function(b:haxe.io.BytesData, offset:Int, length:Int):Void {})
-	@:overload(function(b:jvm.NativeArray<jvm.Char16>):Void {})
-	@:overload(function(b:jvm.NativeArray<Int>, offset:Int, count:Int):Void {})
-	function new(string:String):Void;
+	overload function new(string:String):Void;
+	overload function new(b:haxe.io.BytesData, offset:Int, length:Int, charsetName:String):Void;
+	overload function new(b:haxe.io.BytesData, offset:Int, length:Int):Void;
+	overload function new(b:jvm.NativeArray<jvm.Char16>):Void;
+	overload function new(b:jvm.NativeArray<Int>, offset:Int, count:Int):Void;
 
 	function toUpperCase():String;
 	function toLowerCase():String;
@@ -67,8 +67,8 @@ extern class String implements java.lang.CharSequence {
 
 	private function codePointAt(idx:Int):Int;
 
-	@:overload(function():haxe.io.BytesData {})
-	private function getBytes(encoding:String):haxe.io.BytesData;
+	private overload function getBytes():haxe.io.BytesData;
+	private overload function getBytes(encoding:String):haxe.io.BytesData;
 
 	@:runtime static inline function fromCharCode(code:Int):String {
 		return jvm.StringExt.fromCharCode(code);