function A {
Write-Host "In A"
return "something"
}
# Here, A is called twice
$y = (A) ?? "blabla"
The function A should be called only once.
In A
The function A is called twice.
In A
In A
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
/cc @adityapatwardhan @rjmholt
The LHS here needs to be saved to a temporary variable:
Also
AutomationNull is a static class that stores an instance of PSObject in a static field. This check will never be true.
/cc @SteveL-MSFT for visibility. Double execution could cause some very dangerous side effects. May be a good candidate for inclusion in a servicing update.
:tada:This issue was addressed in #12667, which has now been successfully released as v7.0.2.:tada:
Handy links:
:tada:This issue was addressed in #12667, which has now been successfully released as v7.1.0-preview.4.:tada:
Handy links:
Most helpful comment
/cc @SteveL-MSFT for visibility. Double execution could cause some very dangerous side effects. May be a good candidate for inclusion in a servicing update.