Add pass for const/var checking
This pass replaces !1118 (closed) , working at the level of ast_imperative
: loops have not been translated using functions, assigns have not been translated using shadowing.
Bound variables (in functions, let, matching, recursion) can now have an optional attribute const_or_var
which can be either `Const
([@const]
) or `Var
([@var]
). They are managed as follows in each language:
- In PascaLIGO, depending on whether the bound identifier is
const
orvar
it gets the corresponding attribute when declared. - In ReasonLIGO and CameLIGO, all variables get
`Const
. - In JsLIGO,
const
gets`Const
attribute, all others binders get no attribute.
Then, two passes are run on self_ast_imperative
:
-
vars.ml
: errors on capturing`Var
-variables in functions. -
consts.ml
: errors on assigning`Const
-variables (usingE_assign
).
When printing, only the [@var]
attribute is printed.
In CameLIGO/ReasonLIGO, binders can be endowed with attributes as follows, e.g. the following code
let foo : int -> int -> unit -> int =
fun (x[@var] : int) (y : int) ->
fun (_ : unit) -> x + y
will fail:
File "capture_var_params.mligo", line 2, characters 6-21:
1 | let foo : int -> int -> unit -> int =
2 | fun (x[@var] : int) (y : int) ->
3 | fun (_ : unit) -> x + y
Cannot be captured.
Close #691