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).
Merge request reports
Activity
assigned to @er433
A new deploy preview is available on Netlify at https://2136-519f1d5a--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/636d05cd740e76377677a687
added 1 commit
- e49216c4 - feat: add check for comparable types under set and ticket
added 1 commit
- 0cca7644 - refactor: rename is_comaprable to check_comparable
A new deploy preview is available on Netlify at https://2136-958eba28--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/636d2eba2450d7006cc4a69e
A new deploy preview is available on Netlify at https://2136-7c54d808--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/636d349de094a005cc3d2443
mentioned in commit 7c54d808
A new deploy preview is available on Netlify at https://2136-fe271658--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/636d37ed1b30550873122827
added 3 commits
-
468e8e60...7fb374f7 - 2 commits from branch
dev
- fe9aedba - Merge branch 'dev' into er433/docs/test-comparable
-
468e8e60...7fb374f7 - 2 commits from branch
A new deploy preview is available on Netlify at https://2136-01ea6410--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/636e5c33a3127e2f896c8cc9
A new deploy preview is available on Netlify at https://2136-f39cb738--ligolang.netlify.app, you can view the logs at https://app.netlify.com/sites/ligolang/deploys/637282bbf10f05049acf9ea6
mentioned in commit e4de9cef
unassigned @er433