Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Shadowing bug in inlining affecting foreach #639

Closed
jeromesimeon opened this issue Jul 26, 2019 · 2 comments
Closed

Shadowing bug in inlining affecting foreach #639

jeromesimeon opened this issue Jul 26, 2019 · 2 comments
Assignees
Labels
Type: Bug 🐛 Something isn't working

Comments

@jeromesimeon
Copy link
Member

Describe the bug
Inlining does not handle local variable shadowing properly when within foreach expressions.

To Reproduce

The following zip contains a simple test:
inlinetest.zip

Unzip the file and execute the contract with the following command:

ergorun.js execute model.cto logic.ergo --contract contract.json --request request.json  

For the following expression in the test clause:

    return MyResponse{
			output1: let c = 2; c,
			output2: foreach c in [1,2,3] return c
		}

The result is:

{
    "$class": "org.accordproject.inline.MyResponse",
    "output1": 2,
    "output2": [1, 1, 1],
    "transactionId": "07c93b3c-2750-46aa-a8a7-488cf9ade69c",
    "timestamp": "2019-07-26T00:13:41.028Z"
  }

The local variable c shadows the global constant c properly for the let expression, but not for the foreach expression.

Expected behavior

The expected result should be:

{
    "$class": "org.accordproject.inline.MyResponse",
    "output1": 2,
    "output2": [1, 2, 3],
    "transactionId": "07c93b3c-2750-46aa-a8a7-488cf9ade69c",
    "timestamp": "2019-07-26T00:13:41.028Z"
  }

Desktop (please complete the following information):

  • OS: MacOS
  • Browser N/A
  • Version 0.9
@jeromesimeon jeromesimeon added the Type: Bug 🐛 Something isn't working label Jul 26, 2019
@jeromesimeon jeromesimeon self-assigned this Jul 26, 2019
@jeromesimeon
Copy link
Member Author

The most likely reason for the bug is that the generic mapper for expressions used inside the inlining phase, does not record variables from the foreach expression properly in the context:

The corresponding code is at:

| EForeach loc rs whr fn' =>

Which does not call the ctxt_new_variable_scope.

In contrast, here is the corresponding call for let:

(ergo_map_expr (ctxt_new_variable_scope ctx n v) ctxt_new_variable_scope fn b)

@jeromesimeon
Copy link
Member Author

Addressed in #640

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant