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 03b4e434ef6..0a90085b1d9 100644 --- a/src/typing/typeload.ml +++ b/src/typing/typeload.ml @@ -634,24 +634,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/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); 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