Skip to content

Draft: Xavierm02/discriminating unions

Xavier Montillet requested to merge xavierm02/discriminating-unions into dev

Motivation and Context


const f = (_x: int) => {
  switch ("int") {
    case "int": return 1;
  return 0;

const entry = (p: nat, s: int): [list<operation>, int] => {
  let result = f(p + s);
  return [list([]), result];

yields a Michelson program containing PUSH string "int" ; PUSH string "int" ; COMPARE ; while one might expect the backend to precompute that.


  • Can't have E_union_accessor because the coercions to the lub can't be stored, so we transform it into a match where we can immediately apply these coercions

Context.tapply ?


  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

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)



  • If a new syntax has been introduced, put a message on slack ligo-lsp
  • 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 Xavier Montillet

Merge request reports