Skip to content

Commit f2638f6

Browse files
committed
absorb field monomorphs when cloning ctx.e
closes #11381
1 parent 5829dda commit f2638f6

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

src/context/typecore.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ module TyperManager = struct
278278

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

283295
let clone_for_type_params ctx params =

src/typing/typeloadFunction.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ let type_function_params ctx fd host fname =
3939
let type_function ctx (args : function_arguments) ret e do_display p =
4040
ctx.e.ret <- ret;
4141
ctx.e.opened <- [];
42-
ctx.e.monomorphs <- [];
4342
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]);
4443
args#bring_into_context ctx;
4544
let e = match e with
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
1+
Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be Null<js.lib.PromiseHandler<Dynamic, Int>>
22
Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected'

tests/misc/projects/Issue6790/pretty-fail.hxml.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be js.lib.PromiseHandler<Dynamic, Int>
1+
Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be js.lib.PromiseHandler<Dynamic, Int>
22
Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package unit.issues;
2+
3+
import unit.Test;
4+
5+
class Issue11381 extends Test {
6+
function test() {
7+
var a:Int = func1(1);
8+
var s:String = func1("foo");
9+
eq("foo", s);
10+
}
11+
12+
function func1(a:Dynamic) {
13+
return a;
14+
}
15+
}

0 commit comments

Comments
 (0)