Skip to content

SA1513 triggers in multiline patterns with variable assignment #3319

Open
@crazycrank

Description

@crazycrank

I'm currently writing a source generator where I have some multiline pattern matches with direct variable assignment, that wrongly triggers SA1513:

switch (syntaxNode)
{
    case MethodDeclarationSyntax
    {
        Parent: ClassDeclarationSyntax { Identifier: { ValueText: "ResultExtensions" } },
        Modifiers: var modifiers,
        ParameterList: { Parameters: var parameters },
    } methodDeclarationSyntax: // SA1513 triggers here, but probably shouldnt
        // do stuff here
        break;
    }
}

The same is the case when i have the same assignment in an if statement:

if (syntaxNode is MethodDeclarationSyntax
                  {
                      Parent: ClassDeclarationSyntax { Identifier: { ValueText: "ResultExtensions" } },
                      Modifiers: var modifiers,
                      ParameterList: { Parameters: var parameters },
                  } methodDeclarationSyntax) // SA1513 triggers here, but probably shouldnt
{
    // do stuff here
}

IMHO SA1513 shouldn't trigger in this case. There might be case to force a newline after the pattern, but even that seems to not enhance readability, on the contrary. Having to seperate the variable assignment from the pattern itself as it is now hurts even more. Not having a variable assignment after the pattern works fine and does not trigger the rule, neither in the switch nor the if statement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions