Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate @:overload(function()) syntax #11843

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src-json/warning.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 7 additions & 8 deletions src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions std/jvm/_std/String.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/misc/lua/projects/Issue9402/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-main Main
-lua bin/test.lua
-w -WMetaOverload
--cmd lua bin/test.lua
Loading