Skip to content

Commit

Permalink
Fix frozen lambda captures untracked (#112)
Browse files Browse the repository at this point in the history
* Cosntraint => Constraint

* Gives an error when trying to capture (or use) an untracked function from a frozen context (async/pure lambda).
  • Loading branch information
pikatchu authored Oct 14, 2019
1 parent ad8e1be commit b9681f9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/frontend/skipTypes.sk
Original file line number Diff line number Diff line change
Expand Up @@ -2956,9 +2956,10 @@ private fun is_frozen_map(
}

fun is_frozen_tfun_modifiers(mods: N.Tfun_modifiers): Bool {
(purity, _) = mods;
invariant(!purity.isEmpty(), "impposible tfun");
purity[0] is N.Fpure()
(purity, tracking) = mods;
invariant(!purity.isEmpty(), "imposible tfun");
invariant(!tracking.isEmpty(), "imposible tfun");
purity[0] is N.Fpure() && tracking[0] is N.Ftracked()
}

private fun is_frozen_map_tparam(
Expand Down
8 changes: 5 additions & 3 deletions src/frontend/skipTyping.sk
Original file line number Diff line number Diff line change
Expand Up @@ -2392,15 +2392,15 @@ fun expr_(
(acc, (vty_fixed, (pos1, TAst.Local(n))))
| None() if (SkipNaming.maybeGetFun(n.i1).isSome()) ->
fd = SkipNaming.getFun(n);
(acc1, subst, targs) = TUtils.mk_tparams(next_id, pos1, acc, fd.tparams);
(!acc, subst, targs) = TUtils.mk_tparams(next_id, pos1, acc, fd.tparams);
tracking = SkipNaming.make_tfun_tracking(fd.untracked_);
params_ty = TUtils.make_params_type(
subst,
acc.tparam_constraints,
fd.params,
);
rty = TUtils.type_subst(subst, acc, fd.return_);
ty = (
origTy = (
pos1,
N.Tfun(
Ast.Vnone(),
Expand All @@ -2410,8 +2410,10 @@ fun expr_(
rty,
),
);
level = -1;
(!acc, ty) = check_local_mutable(env, acc, pos1, level, origTy);
e1 = (pos1, TAst.Fun(n, targs));
(acc1, (ty, e1))
(acc, (ty, e1))
| None() if (SkipNaming.maybeGetConst(n.i1).isSome()) ->
ty = SkipNaming.getConst(n).type;
(acc, (ty, (pos1, TAst.Const(n))))
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
dir=$(dirname "$0")

if [[ $BACKEND == "" ]]; then
BACKEND="js"
BACKEND="native"
fi
FILES=$(cd $dir; find . \! \( \( -path ./build -o -path ./native -o -path ./.git \) -prune \) -not -name .#\* -name '*.sk')
TARGETS=$(cd $dir/build; ninja -t targets | sed -e 's/:.*//')
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
File "./typechecking/invalid/frozen_lambda_captures_untracked.sk", line 6, characters 13-15:
You cannot capture this variable
4 |
5 | untracked fun main(): void {
6 | _ = () ~> foo();
| ^^^
7 | }

File "./typechecking/invalid/frozen_lambda_captures_untracked.sk", line 6, characters 13-15:
Mutable because of this position
4 |
5 | untracked fun main(): void {
6 | _ = () ~> foo();
| ^^^
7 | }

File "./typechecking/invalid/frozen_lambda_captures_untracked.sk", line 6, characters 7-17:
Because this closure was declared as pure (~>)
Try '->' instead
4 |
5 | untracked fun main(): void {
6 | _ = () ~> foo();
| ^^^^^^^^^^^
7 | }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
untracked fun foo(): Int {
0
}

untracked fun main(): void {
_ = () ~> foo();
}

0 comments on commit b9681f9

Please sign in to comment.