Skip to content

Commit 6e98a3b

Browse files
committed
Thread argument-types down to internal_check_outer_lval in type.ml, in preparation for trying to infer type params from call args.
1 parent c17ea95 commit 6e98a3b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/boot/me/type.ml

+16-9
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
472472
and internal_check_outer_lval
473473
~mut:(mut:Ast.mutability)
474474
~deref:(deref:bool)
475+
~fn_args:(fn_args:(Ast.ty array) option)
475476
(infer:Ast.ty option)
476477
(lval:Ast.lval)
477478
: (Ast.ty * int) =
@@ -485,11 +486,15 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
485486
demand expected actual;
486487
yield_ty actual
487488
| None, (LTYPE_poly _ as lty) ->
488-
Common.err
489-
None
490-
"not enough context to automatically instantiate the polymorphic \
491-
type '%a'; supply type parameters explicitly"
492-
sprintf_ltype lty
489+
begin
490+
match fn_args with
491+
None ->
492+
Common.err None
493+
"can't auto-instantiate %a" sprintf_ltype lty
494+
| Some args ->
495+
Common.err None "can't auto-instantiate %a on %d args"
496+
sprintf_ltype lty (Array.length args)
497+
end
493498
| Some _, (LTYPE_poly _) ->
494499
(* FIXME: auto-instantiate *)
495500
Common.unimpl
@@ -502,6 +507,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
502507
and generic_check_lval
503508
~mut:(mut:Ast.mutability)
504509
~deref:(deref:bool)
510+
~fn_args:(fn_args:(Ast.ty array) option)
505511
(infer:Ast.ty option)
506512
(lval:Ast.lval)
507513
: Ast.ty =
@@ -521,7 +527,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
521527
| Some t -> Fmt.fmt_to_str Ast.fmt_ty t))
522528
in
523529
let (lval_ty, n_boxes) =
524-
internal_check_outer_lval ~mut:mut ~deref:deref infer lval
530+
internal_check_outer_lval ~mut ~deref ~fn_args infer lval
525531
in
526532
let _ =
527533
iflog cx
@@ -563,9 +569,10 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
563569
and check_lval
564570
?mut:(mut=Ast.MUT_immutable)
565571
?deref:(deref=false)
572+
?fn_args:(fn_args=None)
566573
(lval:Ast.lval)
567574
: Ast.ty =
568-
generic_check_lval ~mut:mut ~deref:deref None lval
575+
generic_check_lval ~fn_args ~mut ~deref None lval
569576

570577
and check_atom ?deref:(deref=false) (atom:Ast.atom) : Ast.ty =
571578
match atom with
@@ -582,7 +589,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
582589
(ty:Ast.ty)
583590
(lval:Ast.lval)
584591
: unit =
585-
ignore (generic_check_lval ?mut:mut ~deref:false
592+
ignore (generic_check_lval ~mut ~deref:false ~fn_args:None
586593
(Some (Ast.TY_mutable ty)) lval)
587594
in
588595

@@ -636,7 +643,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
636643
* returns the return type. *)
637644
let check_fn (callee:Ast.lval) (args:Ast.atom array) : Ast.ty =
638645
let arg_tys = Array.map check_atom args in
639-
let callee_ty = check_lval callee in
646+
let callee_ty = check_lval callee ~fn_args:(Some arg_tys) in
640647
demand_fn (Array.map (fun ty -> Some ty) arg_tys) callee_ty
641648
in
642649

0 commit comments

Comments
 (0)