-
Notifications
You must be signed in to change notification settings - Fork 395
incorrect "variable assinged but never used" when used in $env: expression #1028
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
Comments
I encountered this the other day too. I imagine that the lexically scoped variables will need separate code paths for this:
|
For the |
There is a misunderstanding about variable declaration. When you create a variable as follows: $n = "foo"
${env:$n} you haven't created a variable
if you want to create a dynamic variable in this way, you need to find another way
|
@JamesWTruher Oh, good to know! Thx for the clarification! |
@powercode - is it ok to close this issue? |
My particular use-case involves a less ambiguous scenario. Basically a case where two functions act as an interface to a shared state in a higher scope: $script:stack = [System.Collections.Stack[string]]::new()
function Push-Stack
{
$script:stack.Push($env:PSModulePath)
$env:PSModulePath = $env:PSModulePath + [System.IO.Path]::PathSeparator + $args[0]
}
function Pop-Stack
{
$env:PSModulePath = $script:stack.Pop()
} PSSA gives a warning in
The problem I think is that PSSA doesn't understand variable scopes as well as it should. I imagine that PSSA should essentially treat
But |
FYI I just tried this with the latest version of PSSA and my repro is now fixed |
@rjmholt does this mean that the issue can be closed? |
We should verify again with the current build, but I believe there's still work to be done here for differently scoped variables |
Yes, I think we should close it. The scoping issue is a well known one, I even created a special issue tag for issues related to scoping problem/limitation. |
Before submitting a bug report:
Steps to reproduce
Expected behavior
Actual behavior
If an unexpected error was thrown then please report the full error details using e.g.
$error[0] | Select-Object *
Environment data
The text was updated successfully, but these errors were encountered: