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

Fix @:generic with multiple calls #11619

Merged
merged 3 commits into from
Mar 28, 2024
Merged
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
13 changes: 2 additions & 11 deletions src/typing/generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,9 @@ let type_generic_function ctx fa fcc with_type p =
) monos;
let el = fcc.fc_args in
let gctx = make_generic ctx cf.cf_params monos (Meta.has (Meta.Custom ":debug.generic") cf.cf_meta) p in
let fc_type = build_instances ctx fcc.fc_type p in
let name = cf.cf_name ^ "_" ^ gctx.name in
let params = extract_type_parameters monos in
let clones = List.map (fun ttp ->
let name_path = if (fst ttp.ttp_class.cl_path) = [cf.cf_name] then ([name],ttp.ttp_name) else ttp.ttp_class.cl_path in
clone_type_parameter gctx c.cl_module name_path ttp
) params in
let param_subst = List.map2 (fun ttp ttp' ->
(ttp.ttp_type,ttp')
) params clones in
let param_subst = List.map (fun (t,ttp) -> t,(ttp.ttp_type,None)) param_subst in
let gctx = {gctx with subst = param_subst @ gctx.subst} in
let fc_type = build_instances ctx (generic_substitute_type gctx fcc.fc_type) p in
let unify_existing_field tcf pcf = try
unify_raise tcf fc_type p
with Error ({ err_message = Unify _; err_depth = depth } as err) ->
Expand Down Expand Up @@ -519,7 +510,7 @@ let type_generic_function ctx fa fcc with_type p =
| _ -> true
) cf.cf_meta in
cf2.cf_meta <- (Meta.NoCompletion,[],p) :: (Meta.NoUsing,[],p) :: (Meta.GenericInstance,[],p) :: meta;
cf2.cf_params <- clones
cf2.cf_params <- params
in
let mk_cf2 name =
mk_field ~static:stat name fc_type cf.cf_pos cf.cf_name_pos
Expand Down
17 changes: 17 additions & 0 deletions tests/misc/projects/Issue11608/Test.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Test;

class Test {
static public function main() {}

static function doF2<T>(f: T -> Float) : T {
var arr = [];
arr.doF(f);
arr.doF(f);
return arr.doF(f);
}

@:generic
static function doF<T>(array: Array<T>, f: T -> Float) : T {
return null;
}
}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11608/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-main Test
Loading