Skip to content

Formatting fails when parameter defaults are set to a statement #518

Closed
@cohowap

Description

@cohowap

System Details

  • Operating system name and version: Windows 10 Enterprise 10.0.14393
  • VS Code version: 1.9.1
  • PowerShell extension version: 0.9.0
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.14393.693
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.693
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

When I Format a document that contains a default value (that is actually a statement), formatting differs than if you do not have it (it is left aligned by an additional tab).

In this case, formatted for parameter "$Here" is incorrect, as is any code below it. Removing "$(throw ..)" fixes the issue.

function Do-Something {
  param(
    [Parameter(Position=0)]
    $Over = $(throw "The parameter -Over is required."),
  [Parameter(Position=1)]
  $Here = $(throw "The parameter -Here is required.")
)
}

Attached Logs

Not sure logs are required, this is reproducible on multiple systems. Just paste above and format document with and without the "$(throw ...)" part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions