Skip to content

Commit

Permalink
motoko-san: Let-bound variants
Browse files Browse the repository at this point in the history
This change fixes the Viper translation of let-bound variants by
removing normalization from `infer_exp` in `typing.ml`, thus making the
nominal type accessible in `trans.ml`
  • Loading branch information
int-index committed May 30, 2024
1 parent 150c958 commit 3ab0cee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ and infer_exp' f env exp : T.typ =
if not env.pre then begin
assert (T.normalize t' <> T.Pre);
let e = A.infer_effect_exp exp in
exp.note <- {note_typ = T.normalize t'; note_eff = e}
exp.note <- {note_typ = t'; note_eff = e}
end;
t'

Expand Down
1 change: 1 addition & 0 deletions test/viper/ok/variants.tc.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variants.mo:12.16-12.21: warning [M0194], unused identifier getBW (delete or rename to wildcard `_` or `_getBW`)
10 changes: 10 additions & 0 deletions test/viper/ok/variants.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ adt BW { Black()
adt Pair [A, B]
{ ordered(ordered$0 : A, ordered$1 : B)
swapped(swapped$0 : Pair[B, A]) }
method getBW($Self: Ref)
returns ($Res: BW)
requires $Perm($Self)
ensures $Perm($Self)
{ var x: BW
x := Black();
$Res := x;
goto $Ret;
label $Ret;
}
method get($Self: Ref)
returns ($Res: Pair[Int, BW])
requires $Perm($Self)
Expand Down
1 change: 1 addition & 0 deletions test/viper/ok/variants.vpr.stderr.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variants.mo:12.16-12.21: warning [M0194], unused identifier getBW (delete or rename to wildcard `_` or `_getBW`)
5 changes: 5 additions & 0 deletions test/viper/variants.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ actor Variants {
#swapped : Pair<B, A>;
};

private func getBW(): BW {
let x : BW = #Black;
return x;
};

func idPair<A, B>(p: Pair<A, B>) : Pair<A, B> {
return p;
};
Expand Down

0 comments on commit 3ab0cee

Please sign in to comment.