catala icon indicating copy to clipboard operation
catala copied to clipboard

Name resolution : precedence of local variables or scope variables ?

Open denismerigoux opened this issue 2 years ago • 3 comments

The problem

Consider the following program:

declaration scope X: 
   ...
   
declaration scope Foo:
  x scope X
  internal y content integer
  
scope Foo:
  definition y equals 
    let x equals 0 in 
    x + 1

What does the last x refer to the local variable or the sub-scope ? Right now Catala's name resolution assigns x to be the sub-scope, ignoring the local variable.

A fix

Local variables should always take precedence over scope variables in code, so surface/name_resolution.ml should be changed to reflect that rule.

denismerigoux avatar Aug 16 '22 13:08 denismerigoux

Ugh indeed!!

AltGr avatar Aug 16 '22 14:08 AltGr

Added a related test in #319; but it seems to pass ??

AltGr avatar Aug 19 '22 09:08 AltGr

That's weird. Moreover I can't find where I spotted this in the housing benefits examples. But we can add more unit tests to check for all kind of name precedence bugs in #319.

denismerigoux avatar Aug 19 '22 09:08 denismerigoux