question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SA1513 triggered in switch statement used as part of an operation

See original GitHub issue

Hi,

I get SA1513 triggered in the case below. I’m asked by StyleCop to add a line after final bracket of the switch statement, but I’m expecting the rest of the operation to be inline after the bracket. Here’s an example below reproduced in .NET Core 3.1 or .NET 5. Assuming Foo is an enum

    internal static int FooTest(Foo foo, int a)
        => foo switch
        {
            Foo.Bar => 1,
            Foo.Buzz => 2,
            _ => throw new InvalidOperationException(),
        } << a;

forces me to write:

    internal static int FooTest(Foo foo, int a)
        => foo switch
        {
            Foo.Bar => 1,
            Foo.Buzz => 2,
            _ => throw new InvalidOperationException(),
        }

        << a;

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
karol-grocommented, Jan 13, 2021

Similar issue happens with semicolon. Having code like this:

throw result switch
{
	null => new Exception("b"),
	_ => new Exception("a"),
};

StyleCop (1.2.0-beta.321) suggest following fix:

throw result switch
{
	null => new Exception("b"),
	_ => new Exception("a"),
}

;
0reactions
karol-grocommented, Aug 22, 2023

@DrummingBeb since it looks like a defect, I’d suggest putting it in separate issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

switch Statement (C)
A switch statement causes control to transfer to one labeled-statement in its statement body, depending on the value of expression .
Read more >
Using Switch Expressions in Java
Introduced in Java 13, Switch Expressions offer developers a new way to use switch. See the benefits and potential pitfalls in our tutorial, ......
Read more >
Every case in switch is triggered in JS
JavaScript supports C style switch case fall through, which means unless there is a break specified, it will continue to execute all the ......
Read more >
if and switch statements - select a code path to execute
The `if` and `switch` statements provide branching logic in C#. You use `if, `else` and `switch` to choose the path your program follows....
Read more >
Difference between SWITCH and IF/ELSE- ...
@DavidSchach I personally use a static method in the trigger; that static method is responsible for determining which handler class to execute ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found