Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exported map keys to local scope #377

Merged
merged 4 commits into from
Dec 11, 2024
Merged

Conversation

irh
Copy link
Contributor

@irh irh commented Dec 11, 2024

This PR fixes an inconsistency in behaviour between exporting values using assignment or maps.

x = -1
export x = 123 
print x # The local value of `x` gets updated by the assignment export
# 123

y = -1
export {y: 99}
print y # The local of value of `y` wasn't updated by the map export
# -1

This happens because map entries typically don't get added to the local scope. The runtime will look for a local value first, and then check the exports map if one isn't found. In this case, a local y is available, so the exported value isn't used. Exporting via a map is available for convenience and shouldn't have a difference in behaviour, so this PR ensures that map-export entries get assigned locally, updating existing variables if they exist.

irh added 4 commits December 11, 2024 14:52
This makes maps consistent with export assignment: exported values
should be available locally, and should update matching local variables.
@irh irh force-pushed the add-exported-map-keys-to-local-scope branch from 9c4be17 to 42b9d8f Compare December 11, 2024 15:06
@irh irh merged commit 338c1f6 into main Dec 11, 2024
8 checks passed
@irh irh deleted the add-exported-map-keys-to-local-scope branch December 11, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant