Skip to content

Tezos.create_contract with usage of modules: free variables calculation in C_CREATE_CONTRACT typing

Free variables are calculated when typing C_CREATE_CONTRACT. However, this calculation breaks with modules:

$ cat create_contract_toplevel.mligo 
type return = operation list * string

let main (action, store : string * string) : return =
  module Foo = struct
    let store = store
  end in
  let toto : operation * address = Tezos.create_contract
    (fun (p, s : nat * string) -> (([] : operation list), Foo.store)) 
    (None: key_hash option) 
    300tz 
    "un"
  in
  ([toto.0], store)
$ docker run --rm -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:0.39.0 compile contract create_contract_toplevel.mligo
An internal error ocurred. Please, contact the developers.
Corner case: gen#12 not found in env.

(as opposed to what happens in original create_contract_toplevel.mligo with store:

File "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8:
  3 | let main (action, store : string * string) : return =
  4 |   let toto : operation * address = Tezos.create_contract
  5 |     (fun (p, s : nat * string) -> (([] : operation list), store)) 
  6 |     (None: key_hash option) 
  7 |     300tz 
  8 |     "un"
  9 |   in

Free variable 'store' is not allowed in CREATE_CONTRACT lambda

)