Skip to content

Resolve "Wrong references in `ligo info get-scope`"

Motivation and Context

There is a bug is get-scope related reference of top-level binding not getting updated when it is shadowed by local binding.

Description

This MR fixes the issue by maintaning separate list for top-level & local bindings separately.

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

For a ligo program like

let x = 42
let f x = 0
let g = x

Before

$ ligo.59 info get-scope x.mligo --format dev --with-types
Scopes:
[  ] File "x.mligo", line 1, characters 8-10
[ x#1  ] File "x.mligo", line 2, characters 10-11
[ f#2 x#0  ] File "x.mligo", line 3, characters 8-9

Variable definitions:
(f#2 -> f) 
Range: File "x.mligo", line 2, characters 4-5 
Body Range: File "x.mligo", line 2, characters 6-7 
Content: |resolved: ∀ gen#563 : * . gen#563 -> int|
references: []
(g#3 -> g) 
Range: File "x.mligo", line 3, characters 4-5 
Body Range: File "x.mligo", line 3, characters 8-9 
Content: |resolved: int|
references: []
(x#0 -> x) 
Range: File "x.mligo", line 1, characters 4-5 
Body Range: File "x.mligo", line 1, characters 8-10 
Content: |resolved: int|
references: [] <---- The reference of top-level binding is not updated
(x#1 -> x) 
Range: File "x.mligo", line 2, characters 6-7 
Body Range: File "x.mligo", line 2, characters 10-11 
Content: |resolved: gen#563|
references: File "x.mligo", line 3, characters 8-9 <---- The reference of local binding is updated :(
Type definitions:
Module definitions:

After

$ ligo info get-scope x.mligo --with-types --format dev
Scopes:
[  ] File "x.mligo", line 1, characters 8-10
[ x#1  ] File "x.mligo", line 2, characters 10-11
[ f#2 x#0  ] File "x.mligo", line 3, characters 8-9

Variable definitions:
(f#2 -> f) 
Range: File "x.mligo", line 2, characters 4-5 
Body Range: File "x.mligo", line 2, characters 6-7 
Content: |resolved: ∀ gen#563 : * . gen#563 -> int|
references: []
(g#3 -> g) 
Range: File "x.mligo", line 3, characters 4-5 
Body Range: File "x.mligo", line 3, characters 8-9 
Content: |resolved: int|
references: []
(x#0 -> x) 
Range: File "x.mligo", line 1, characters 4-5 
Body Range: File "x.mligo", line 1, characters 8-10 
Content: |resolved: int|
references: File "x.mligo", line 3, characters 8-9 <---- The reference of level binding is updated correctly
(x#1 -> x) 
Range: File "x.mligo", line 2, characters 6-7 
Body Range: File "x.mligo", line 2, characters 10-11 
Content: |resolved: gen#563|
references: []
Type definitions:
Module definitions:

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).
  • 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 #1581 (closed)

Edited by Melwyn Saldanha

Merge request reports