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

compiler: vars fixes #1695

Merged
merged 2 commits into from
Nov 1, 2023
Merged

compiler: vars fixes #1695

merged 2 commits into from
Nov 1, 2023

Conversation

alixander
Copy link
Collaborator

@alixander alixander commented Nov 1, 2023

  1. Fix missing spread substitution var
  2. Change vars scoping

For 2:

The compiler compiles the IR first, then resolves substitutions.

The vars stack is built-up incrementally, so a var is only visible if it's been declared before you access it.

The initial IR compilation coalesces the fields, so that x1, though accessing a var after the var's declaration, is seen as being defined before the var's declaration.

I don't actually think in a declarative language you should be able to change vars mid-way. Changed so that all vars within the same scope are coalesced first.

closes #1641

@alixander alixander changed the title Vars panic compiler: vars fixes Nov 1, 2023
Copy link
Contributor

@gavin-ts gavin-ts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests look good I don't really know this code that well but it looks good

d2ir/compile.go Outdated Show resolved Hide resolved
d2ir/compile.go Show resolved Hide resolved
@alixander alixander merged commit 65c4849 into terrastruct:master Nov 1, 2023
3 checks passed
@alixander alixander deleted the vars-panic branch November 1, 2023 20:31
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.

panic using var on object declared before vars
2 participants