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

No declaration found for local variable when using list comprehensions #1867

Open
1 task
Cih2001 opened this issue Nov 12, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working

Comments

@Cih2001
Copy link

Cih2001 commented Nov 12, 2024

Language Server Version

v0.35.0

Terraform Version

Terraform v1.9.8 on darwin_arm64

Client Version

Neovim (builtin lsp)

Terraform Configuration

locals {

  # This works fine
  # service_accounts = [
  #   "serviceAccount:[email protected]",
  # ]

  # but this doesn't:
  service_accounts = [for sa in [
    "[email protected]",
  ] : "serviceAccount:${sa}"]

  subscribers = local.service_accounts
}

provider "null" {}

resource "null_resource" "example" {}

Steps to Reproduce

  1. Save the above config in a file
  2. Run terraform init
  3. See the error in your editor

Expected Behavior

No error being reported

Actual Behavior

An error is reported at the line including subscribers = local.service_accounts. The error message is:
Terraform: No declaration found for "local.service_accounts"

Additionally, since the local variable is not identified, additional functionalities such as go to definitions doesn't work for it.

Gist

No response

Workarounds

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@Cih2001 Cih2001 added the bug Something isn't working label Nov 12, 2024
@Cih2001
Copy link
Author

Cih2001 commented Nov 12, 2024

Well I tracked this down to

_, ok = pathCtx.ReferenceTargets.Match(localOrigin)

Match function fails to match the local variable, even though it is in the reference targets. Seems that the issue is on hcl-lang module. I may spend more time on this tomorrow to find out where the issue is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant