Skip to content

Commit

Permalink
absorb field monomorphs when cloning ctx.e
Browse files Browse the repository at this point in the history
closes #11381
  • Loading branch information
Simn committed Dec 19, 2024
1 parent 5829dda commit f2638f6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ module TyperManager = struct

let clone_for_expr ctx curfun in_function =
let e = create_ctx_e curfun in_function in
begin match curfun with
| FunMember | FunMemberAbstract | FunStatic | FunConstructor ->
(* Monomorphs from field arguments and return types are created before
ctx.e is cloned, so they have to be absorbed here. A better fix might
be to clone ctx.e earlier, but that comes with its own challenges. *)
e.monomorphs <- ctx.e.monomorphs;
ctx.e.monomorphs <- []
| FunMemberAbstractLocal | FunMemberClassLocal ->
(* We don't need to do this for local functions because the cloning happens
earlier there. *)
()
end;
create ctx ctx.m ctx.c ctx.f e PTypeField ctx.type_params

let clone_for_type_params ctx params =
Expand Down
1 change: 0 additions & 1 deletion src/typing/typeloadFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ let type_function_params ctx fd host fname =
let type_function ctx (args : function_arguments) ret e do_display p =
ctx.e.ret <- ret;
ctx.e.opened <- [];
ctx.e.monomorphs <- [];
enter_field_typing_pass ctx.g ("type_function",fst ctx.c.curclass.cl_path @ [snd ctx.c.curclass.cl_path;ctx.f.curfield.cf_name]);
args#bring_into_context ctx;
let e = match e with
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue6790/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected'
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue6790/pretty-fail.hxml.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

6 | p.then(x -> 10, e -> "");
| ^^^^^^^
| (e : Unknown<0>) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
| (e : Dynamic) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
| For optional function argument 'onRejected'

2 changes: 1 addition & 1 deletion tests/misc/projects/Issue7655/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be js.lib.PromiseHandler<Dynamic, Int>
Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be js.lib.PromiseHandler<Dynamic, Int>
Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected'
15 changes: 15 additions & 0 deletions tests/unit/src/unit/issues/Issue11381.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package unit.issues;

import unit.Test;

class Issue11381 extends Test {
function test() {
var a:Int = func1(1);
var s:String = func1("foo");
eq("foo", s);
}

function func1(a:Dynamic) {
return a;
}
}

0 comments on commit f2638f6

Please sign in to comment.