From d073103578b7e9dc433adbf7feff7e23883fe05c Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Mon, 24 Jun 2024 11:56:25 +0200 Subject: [PATCH] Typecheck operator args bottom-up after monomorphisation (?) --- compiler/shared_ast/typing.ml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/shared_ast/typing.ml b/compiler/shared_ast/typing.ml index 302974db..aa167519 100644 --- a/compiler/shared_ast/typing.ml +++ b/compiler/shared_ast/typing.ml @@ -895,15 +895,17 @@ and typecheck_expr_top_down : let args = Operator.kind_dispatch (Mark.set pos_e op) ~polymorphic:(fun op -> - (* Type the operator first, then right-to-left: polymorphic operators - are required to allow the resolution of all type variables this - way *) - if not env.flags.assume_op_types then - unify ctx e (polymorphic_op_type op) t_func - else unify ctx e (polymorphic_op_return_type ctx e op t_args) tau; - List.rev_map2 - (typecheck_expr_top_down ctx env) - (List.rev t_args) (List.rev args)) + if env.flags.assume_op_types then ( + unify ctx e (polymorphic_op_return_type ctx e op t_args) tau; + List.rev_map (typecheck_expr_bottom_up ctx env) (List.rev args)) + else ( + (* Type the operator first, then right-to-left: polymorphic + operators are required to allow the resolution of all type + variables this way *) + unify ctx e (polymorphic_op_type op) t_func; + List.rev_map2 + (typecheck_expr_top_down ctx env) + (List.rev t_args) (List.rev args))) ~overloaded:(fun op -> (* Typing the arguments first is required to resolve the operator *) let args' = List.map2 (typecheck_expr_top_down ctx env) t_args args in