vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Erroneous variable assigned but never used

Open shawnr13 opened this issue 8 years ago • 2 comments

Issue Type: Bug

Setting a variable inside a foreach-object loop, it shows the variable as assigned but never used, when it is used outside of the foreach. Example for replication:

$Array |ForEach-Object {$NewVar = 1};$NewVar

My original problem the first time I set $Added, it has no green squiggle line and appears fine (it recognizes the variable is used later on), but within the foreach-object the same variable is shown as being assigned but never used.:

$Added = 0 If ($Adds) {$Adds |ForEach-Object {Try {$Added += 1}Catch {}}} $AddsElement.SetAttribute("Success",$Added)

Extension version: 1.7.0 VS Code version: Code 1.24.1 (24f62626b222e9a8313213fb64b10d741a326288, 2018-06-13T17:51:32.889Z) OS version: Windows_NT x64 10.0.15063

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz (8 x 2904)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 31.88GB (22.61GB free)
Process Argv C:\Program Files\Microsoft VS Code\Code.exe
Screen Reader no
VM 0%
![image](https://user-images.githubusercontent.com/2037684/41980862-8a85ca12-79f5-11e8-923c-82fb383e22bd.png)

shawnr13 avatar Jun 27 '18 14:06 shawnr13

after another search, I DID find the same issue. https://github.com/PowerShell/PSScriptAnalyzer/issues/827 Thumbs upping that one and closing this one.

shawnr13 avatar Jun 27 '18 14:06 shawnr13

From the looks of things, this should be fixed in our next release

rjmholt avatar Jun 27 '18 19:06 rjmholt