diff --git a/src/context/typecore.ml b/src/context/typecore.ml index c2b86c37b1b..550e9de8a6c 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -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 = diff --git a/src/typing/typeloadFunction.ml b/src/typing/typeloadFunction.ml index ddf7596b7bb..153bbe524ea 100644 --- a/src/typing/typeloadFunction.ml +++ b/src/typing/typeloadFunction.ml @@ -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 diff --git a/tests/misc/projects/Issue6790/compile-fail.hxml.stderr b/tests/misc/projects/Issue6790/compile-fail.hxml.stderr index d5cfc5dfcee..74f0f2045dd 100644 --- a/tests/misc/projects/Issue6790/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue6790/compile-fail.hxml.stderr @@ -1,2 +1,2 @@ -Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be Null> +Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be Null> Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected' diff --git a/tests/misc/projects/Issue6790/pretty-fail.hxml.stderr b/tests/misc/projects/Issue6790/pretty-fail.hxml.stderr index 8b523e3634e..baa8bb4b513 100644 --- a/tests/misc/projects/Issue6790/pretty-fail.hxml.stderr +++ b/tests/misc/projects/Issue6790/pretty-fail.hxml.stderr @@ -2,6 +2,6 @@ 6 | p.then(x -> 10, e -> ""); | ^^^^^^^ - | (e : Unknown<0>) -> String should be Null> + | (e : Dynamic) -> String should be Null> | For optional function argument 'onRejected' diff --git a/tests/misc/projects/Issue7655/compile-fail.hxml.stderr b/tests/misc/projects/Issue7655/compile-fail.hxml.stderr index 9acbe3c7b8e..096bd492d87 100644 --- a/tests/misc/projects/Issue7655/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue7655/compile-fail.hxml.stderr @@ -1,2 +1,2 @@ -Mismatch.hx:6: characters 19-26 : (e : Unknown<0>) -> String should be js.lib.PromiseHandler +Mismatch.hx:6: characters 19-26 : (e : Dynamic) -> String should be js.lib.PromiseHandler Mismatch.hx:6: characters 19-26 : ... For optional function argument 'onRejected' diff --git a/tests/unit/src/unit/issues/Issue11381.hx b/tests/unit/src/unit/issues/Issue11381.hx new file mode 100644 index 00000000000..3899a4a4c4c --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11381.hx @@ -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; + } +}