Skip to content

return on the RHS of an assignment ignores the assignment #13146

@mklement0

Description

@mklement0

Note: This may be an exotic scenario that is easily avoided (no reason to ever use return this way), but I just came across it on Stack Overflow, and the behavior is surprising and unhelpful.

Steps to reproduce

# The assignment is *ignored* due to `return`, and the output goes straight to the success output stream.
$var = return 'foo'

$var | Should -BeExactly 'foo'

Expected behavior

The test should succeed.

Actual behavior

The test fails, because the assignment is ignored (the variable isn't even created) due to use of return.
The output goes straight to the success output stream and therefore prints to the display here.

Environment data

PowerShell Core 7.1.0-preview.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions