Skip to content

Improve error message when compiling functions which capture meta-LIGO types

E. Rivas requested to merge er433/fix/obj_check_on_func into dev

Motivation and Context

When compiling to Michelson a functional value (in the testing framework), we check that the expression is only "object LIGO". However, no check is performed for the env. captured by the function.

Currently, in case the env. contains a ref. to "meta LIGO", this fails with an unhelpful error.

Description

In this MR we enforce recursively checking the env. for "object LIGO".

Other changes:

  • Error message has been improved.
  • We generate a tag using ppx_is to check for meta-LIGO types.
  • An interface for environment.ml in the interpreter.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

Example file

$ cat test_capture_meta_type.mligo
type t = { x : int ; y : (unit, unit) typed_address }

let main ((_, _) : unit * unit) : operation list * unit = [], ()

let ta, _, _ =
  Test.originate main () 0tez

let v = { x = 42 ; y = ta }

let w = v.x

let f = fun (_ : unit) -> v.x

let g = fun (_ : unit) -> f ()

let test = Test.eval g

Before fix

$ ligo run test test_capture_meta_type.mligo 
File "test_capture_meta_type.mligo", line 16, characters 11-22:
 15 | 
 16 | let test = Test.eval g

Cannot decompile value KT1KAUcMCQs7Q4mxLzoUZVH9yCCLETERrDtj of type typed_address (unit ,
unit)

After fix

$ ligo run test test_capture_meta_type.mligo
File "test_capture_meta_type.mligo", line 12, characters 26-27:
 11 | 
 12 | let f = fun (_ : unit) -> v.x
 13 | 

Invalid usage of a Test type: typed_address (unit ,
unit) in record[x -> int , y -> typed_address (unit , unit)] cannot be translated to Michelson.

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas

Merge request reports

Loading