PR https://github.com/PowerShell/PowerShell/pull/13361 missed one aspect of what is was trying to fix, namely what was originally reported in #10512:
How $? is set in an external-program call should solely depend on the process exit code, irrespective of whether there is stderr output and _whether or not stderr output is redirected_.
It is the latter that's still a problem, which matters primarily with respect to && and ||:
# On Unix
PS> sh -c 'ls nosuch; :' 2>$null || 'why did I get here?'
why did I get here?
# On Unix
sh -c 'ls nosuch; :' 2>$null; $? | Should -BeTrue
The test should succeed:
Since the _exit code_ of the sh command is 0, $? should be $true - irrespective of the presence of stderr output, _whether redirected or not_.
The test fails, because the presence of _redirected_ stderr output unexpectedly set $? to `$false
Expected $true, but got $false.
PowerShell Core 7.1.0-preview.5
Since @PowerShell/powershell-committee agreed that stderr is not an indicator of an error, it makes sense to not set $? to false.
:tada:This issue was addressed in #13395, which has now been successfully released as v7.1.0-preview.7.:tada:
Handy links:
Most helpful comment
Since @PowerShell/powershell-committee agreed that stderr is not an indicator of an error, it makes sense to not set
$?to false.