Skip to content

Bugfix : Resolving module aliasing for nested modules

Motivation and Context

The current implementation of aggregation use module aliases' resolution before removing the module in order to avoid duplicating effectful declaration. However the current naive implementation was incomplete and didn't resolved aliases correctly when dealing with nested modules.

module A = struct
  module B = struct
    let nested : int = 0
  end
  module Bx = B
end

let main (action, store : int * int) : operation list * int =
  [], A.Bx.nested

Here the algorithem resolved A.Bx.nested in B.nested instead of A.B.nested as if B was declared at the top-level leading to not being able to compile.

The issues was related to not storing path for modules correctly in Aliases.t which was first solved but lead to further bug in

module A = struct
  module B = struct
    let nested : int = 0
  end
  module Bx = B
  let toto = Bx.nested
end

The aliasing of Bx.nested was resolved as A.B.nested instead of B.nested which was leading to many of your current test failing, while they were passing before (the resolution was correct before because the module path of Bx was wrongly recorded as [B]).

This was solve by applying a "path difference" in module_accessor between the current path "[A]" and the stored path "[B;A]"

A "nested_modules.mligo" have been added in the test which should cover most scenario, and should be extended if we find new ones.

Description

Fix some bug when compiling nested modules and nested module access

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

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

Loading