Skip to content

Resolve "Functional record update is broken for nested records"

Motivation and Context

Description

Component

  • 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)

Changelog

The change fixes a bug in record update

Example

type level1 = {
  foo : int;
  bar : int;
  buz : int;
}

type level2 = {
  l1 : level1;
  fiz : int;
}

type level3 = {
  l2 : level2;
  buz : int;
}

let update (s , n: level3 * int) : level3 =
  { s with
    buz = n;
    l2.fiz = n;
    l2.l1.foo = n;
    l2.l1.bar = n;
  }

let test () : level3 =
  let s : level3 = {
    buz = 0;
    l2 = { 
      fiz = 0;
      l1 = {
        foo = 0;
        bar = 0;
        buz = 0;
      }
    }
  } in
  let s1 = update (s, 5) in
  let () = assert (s1.buz = 5) in
  let () = assert (s1.l2.fiz = 5) in
  let () = assert (s1.l2.l1.bar = 5) in
  let () = assert (s1.l2.l1.foo = 5) in
  s1

Before (0.68.0)

$ ligo.68 run interpret 'test ()' --init-file update.mligo 
failed with: "failed assertion"

After

$ ligo run interpret 'test ()' --init-file update.mligo 
record[buz -> 5 ,
       l2 -> record[fiz -> 5 , l1 -> record[bar -> 5 , buz -> 0 , foo -> 5]]]

Checklist:

  • 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).

Closes #1956 (closed)

Edited by Melwyn Saldanha

Merge request reports