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.

IDE0066 (switch pattern) code fix is incorrect

See original GitHub issue

Version Used: 16.8.0 Preview 3.0

Steps to Reproduce:

The following snippet

switch (invocation.TargetMethod.Name)
{
	case "Last":
    case "First":
    case "Count":
        return true;
    default:
        return false;
}

gets refactored into the following form:

return invocation.TargetMethod.Name switch
{
    "Last" => true,
    _ => false,
};

which is incorrect.

Expected Behavior:

All cases are correctly converted.

Actual Behavior:

The code fix only take the first case declared.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
CyrusNajmabadicommented, Sep 24, 2020

Doesn’t repro for me either. Likely fixed at some point. Have created test to validate this is workign and will not regress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IDE0066 Suggests code that doesn't compile for implicitly ...
So the switch expression's input type is C . The constant pattern "A" is converted to the input type, in this case using...
Read more >
IDE0066: Use switch expression - .NET
In this article ; Title, Use switch expression ; Category, Style ; Subcategory, Language rules (pattern matching preferences) ; Applicable languages ...
Read more >
c# - Why does Visual Studio 2019 recommend a switch ...
If we used a switch statement we'd have to say something like this: string description = null; switch(reason) { case Reasons.
Read more >
Untitled
I'd recommend updating your switch statement example to use the discard pattern for the cases: case Type1 _:, case Type2 _: etc. crepid...
Read more >
Untitled
Patterns - Pattern matching using the is and switch expressions. if and switch statements - select a code path to execute Web21 thg...
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