Add check for non-comparable types under `set` and `ticket`
Motivation and Context
Currently LIGO fails with an error on type-checking when compiling a contract that applies set
or ticket
to a non-comparable type:
$ cat not_comparable.mligo
let main ((_u, s) : (int set) set * unit) : operation list * unit = ([] : operation list), s
$ ligo compile contract not_comparable.mligo
Error(s) occurred while type checking the contract:
At (unshown) location 2, ill formed type:
1: { parameter (set (set int)) ;
2: storage unit ;
3: code { CDR ; NIL operation ; PAIR } }
At line 1 characters 17 to 25,
comparable type expected.Type set int is not comparable.
This is not a very helpful message for the user, as the locations warned in the error refer to Michelson and not to LIGO.
Description
This MR introduces a check at 15-self_mini_c
.
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
Before change
$ ligo compile contract not_comparable.mligo
Error(s) occurred while type checking the contract:
At (unshown) location 2, ill formed type:
1: { parameter (set (set int)) ;
2: storage unit ;
3: code { CDR ; NIL operation ; PAIR } }
At line 1 characters 17 to 25,
comparable type expected.Type set int is not comparable.
After change
$ ligo compile contract not_comparable.mligo
File "not_comparable.mligo", line 1, characters 21-28:
1 | let main ((_u, s) : (int set) set * unit) : operation list * unit = ([] : operation list), s
The set constructor needs a comparable type argument, but it was given a non-comparable one.
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). -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas