Skip to content

Commit 09417f8

Browse files
committed
Typecheck function patterns
1 parent c40fed5 commit 09417f8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/boot/me/type.ml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,12 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
264264
Hashtbl.replace cx.Semant.ctxt_all_defns defn_id
265265
(Semant.DEFN_slot new_slot);
266266
inferred
267+
| TYPAT_fn arg_tys, Some actual ->
268+
ignore (demand_fn (Array.map (fun ty -> Some ty) arg_tys) actual);
269+
actual
267270
| TYPAT_wild, Some actual -> actual
268-
| TYPAT_wild, None ->
271+
| TYPAT_fn _, None | TYPAT_wild, None ->
269272
Common.err None "can't infer any type for this slot"
270-
| TYPAT_fn _, _ ->
271-
Common.unimpl None "sorry, fn type patterns aren't implemented"
272273
in
273274

274275
let internal_check_mod_item_decl
@@ -493,11 +494,9 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
493494
| TYPAT_ty expected, LTYPE_mono actual ->
494495
demand expected actual;
495496
yield_ty actual
496-
| TYPAT_fn _, LTYPE_mono _ ->
497-
(* FIXME: typecheck *)
498-
Common.unimpl
499-
None
500-
"sorry, function type patterns aren't typechecked yet"
497+
| TYPAT_fn arg_tys, LTYPE_mono actual ->
498+
ignore (demand_fn (Array.map (fun ty -> Some ty) arg_tys) actual);
499+
yield_ty actual
501500
| TYPAT_wild, (LTYPE_poly _ as lty) ->
502501
Common.err
503502
None
@@ -661,7 +660,13 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
661660
* returns the return type. *)
662661
let check_fn (callee:Ast.lval) (args:Ast.atom array) : Ast.ty =
663662
let arg_tys = Array.map check_atom args in
664-
let callee_ty = check_lval callee in
663+
let callee_ty =
664+
generic_check_lval
665+
~mut:Ast.MUT_immutable
666+
~deref:false
667+
(TYPAT_fn arg_tys)
668+
callee
669+
in
665670
demand_fn (Array.map (fun ty -> Some ty) arg_tys) callee_ty
666671
in
667672

0 commit comments

Comments
 (0)