From 68447c25f15d8d189dcb6366631e323bce7e0bdf Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 26 Nov 2024 09:13:16 +0100 Subject: [PATCH 1/2] this will be terrible --- src-json/warning.json | 5 +++++ src/typing/typeload.ml | 15 +++++++-------- std/jvm/_std/Reflect.hx | 1 + std/jvm/_std/String.hx | 14 +++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src-json/warning.json b/src-json/warning.json index fa322c7bc9e..ed07e0f2106 100644 --- a/src-json/warning.json +++ b/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" diff --git a/src/typing/typeload.ml b/src/typing/typeload.ml index b2fb546a2ba..24c0fd3c025 100644 --- a/src/typing/typeload.ml +++ b/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 diff --git a/std/jvm/_std/Reflect.hx b/std/jvm/_std/Reflect.hx index 64f5529bacd..6894b1df951 100644 --- a/std/jvm/_std/Reflect.hx +++ b/std/jvm/_std/Reflect.hx @@ -207,6 +207,7 @@ class Reflect { } @:overload(function(f:Array->Void):Dynamic {}) + @:haxe.warning("-WMetaOverload") public static function makeVarArgs(f:Array->Dynamic):Dynamic { return new jvm.Closure.VarArgs((cast f : jvm.Function)); } diff --git a/std/jvm/_std/String.hx b/std/jvm/_std/String.hx index 5ad40632939..09a56c118e4 100644 --- a/std/jvm/_std/String.hx +++ b/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):Void {}) - @:overload(function(b:jvm.NativeArray, 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):Void; + overload function new(b:jvm.NativeArray, 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); From ac5dac2c964694c10c34e4927eba9ef3d0c880a8 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 5 Dec 2024 10:51:56 +0100 Subject: [PATCH 2/2] dodge lua fail --- tests/misc/lua/projects/Issue9402/compile.hxml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/misc/lua/projects/Issue9402/compile.hxml b/tests/misc/lua/projects/Issue9402/compile.hxml index 0fa80d924ca..284fc1dd7d5 100644 --- a/tests/misc/lua/projects/Issue9402/compile.hxml +++ b/tests/misc/lua/projects/Issue9402/compile.hxml @@ -1,3 +1,4 @@ -main Main -lua bin/test.lua +-w -WMetaOverload --cmd lua bin/test.lua \ No newline at end of file