Skip to content

Commit

Permalink
fix: promote parameters that are bounded with function types (#4617)
Browse files Browse the repository at this point in the history
so that execution can observe

fixes #4616
  • Loading branch information
ggreif authored Jul 15, 2024
1 parent 42ad13d commit 55cefc1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Motoko compiler changelog

## 0.11.3 (2024-07-XX)

* motoko (`moc`)

* bugfix: Corrects the interpreter (and compiler) to recognise certain type parameters as callable function types (#4617).

## 0.11.2 (2024-07-06)

* motoko (`moc`)
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10577,7 +10577,7 @@ and compile_prim_invocation (env : E.t) ae p es at =
begin match p, es with
(* Calls *)
| CallPrim _, [e1; e2] ->
let sort, control, _, arg_tys, ret_tys = Type.as_func e1.note.Note.typ in
let sort, control, _, arg_tys, ret_tys = Type.(as_func (promote e1.note.Note.typ)) in
let n_args = List.length arg_tys in
let return_arity = match control with
| Type.Returns -> List.length ret_tys
Expand Down
2 changes: 1 addition & 1 deletion src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ let as_func_sub default_s default_arity t = match promote t with
let as_mono_func_sub t = match promote t with
| Func (_, _, [], ts1, ts2) -> seq ts1, seq ts2
| Non -> Any, Non
| _ -> invalid "as_func_sub"
| _ -> invalid "as_mono_func_sub"
let as_async_sub s default_scope t = match promote t with
| Async (s0, t1, t2) when s = s0 -> (t1, t2)
| Non -> default_scope, Non (* TBR *)
Expand Down
2 changes: 1 addition & 1 deletion src/mo_values/call_conv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let async_cc s n m = { sort = Shared s; control = Promises; n_args = n; n_res =
let replies_cc s n m = { sort = Shared s; control = Replies; n_args = n; n_res = m}

let call_conv_of_typ typ =
match typ with
match promote typ with
| Func (sort, control, tbds, dom, res) ->
{ sort; control; n_args = List.length dom; n_res = List.length res }
| Non ->
Expand Down
3 changes: 3 additions & 0 deletions test/run/contra-bound.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func foo<T, K <: T -> ()>(k : K, v : T) = k v;

foo<Nat, Int -> ()>(func(i : Int) {}, 1);

0 comments on commit 55cefc1

Please sign in to comment.