Skip to content

hclwrite: find traversals inside object-construct expressions - #841

Merged
jbardin merged 1 commit into
hashicorp:mainfrom
lenamonj:hclwrite-object-cons-variables
Oct 13, 2026
Merged

jbardin merged 1 commit into
hashicorp:mainfrom
lenamonj:hclwrite-object-cons-variables

Conversation

@lenamonj

Copy link
Copy Markdown
Contributor

Description

Since #810, parseObjectConsExpr parses each item's key and value into its own Expression, so the object's wrapping Expression holds no traversals, Expression.Variables returns nothing for it and RenameVariablePrefix leaves it unchanged. This walks the object's items so both see the keys' and values' traversals in source order. A naked identifier key is a literal, as in hclsyntax, so its traversal is dropped at parse time and is neither reported nor renamed.

Related Issue

Fixes #840.

How Has This Been Tested?

TestExpressionVariablesObjectCons covers nine object shapes and checks that hclwrite reports the same variable count as hclsyntax for each. Seven of the nine cases fail on main at 4932c14 and all pass with this change. go test -race ./..., make check and golangci-lint v2.5.0 pass.

Since hashicorp#810, parseObjectConsExpr parses each item's key and value into
its own Expression, so the object's wrapping Expression held no
traversals, Expression.Variables returned nothing for it and
RenameVariablePrefix left it unchanged. Walk the items so both see the
keys' and values' traversals in source order. A naked identifier key
is a literal, as in hclsyntax, so its traversal is dropped at parse
time.
@lenamonj
lenamonj requested a review from a team as a code owner September 25, 2026 11:21
@hashicorp-cla-app

hashicorp-cla-app Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@jbardin jbardin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@jbardin
jbardin merged commit d3e7bdf into hashicorp:main Oct 13, 2026
1 check passed
@lenamonj
lenamonj deleted the hclwrite-object-cons-variables branch October 13, 2026 22:38
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.

hclwrite: Expression.Variables and RenameVariablePrefix miss traversals inside an object value since #810

2 participants