Skip to content

$using variable should support method call on it #10876

@daxian-dbw

Description

@daxian-dbw

$using: prefixed variables are used in Foreach-Object -Parallel and Start-ThreadJob to pass value of reference types. Given the value is passed by reference, it's natural to call method on it directly in a thread job or script running in another Runspace, and thus we should remove the semantics check and allow expression to be used on the $using: variable.

Steps to reproduce

{ $using:blah.Add() }

Expected behavior

No error thrown.

Actual behavior

PS> { $using:blah.Add() }
At line:1 char:3
+ { $using:blah.Add() }
+   ~~~~~~~~~~~~~~~~~
Expression is not allowed in a Using expression.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidUsingExpression

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.4
PSEdition                      Core
GitCommitId                    7.0.0-preview.4
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

Labels

Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions