switch case without default no longer compiles in visual studio 2019 [c#] #35011
Labels
Area-Compilers
Bug
Developer Community
The issue was originally reported on https://developercommunity.visualstudio.com
VSF_TYPE_MARKDOWNThe following code compiles fine in Visual Studio 2017, but not in Visual Studio 2019. Is there a default compiler option that has changed which can resolve this?
There is also a Stack Overflow ticket for this item:
https://stackoverflow.com/questions/55541269/why-does-a-switch-case-statement-on-a-string-constant-require-a-default-in-visua
This issue has been moved from https://developercommunity.visualstudio.com/content/problem/520522/switch-case-without-default-no-longer-compiles-in.html
VSTS ticketId: 841662
These are the original issue comments:
Martin Eyles on 4/6/2019, 05:37 AM (10 days ago):
In Visual Studio 2017, the output of the build is:
1>------ Rebuild All started: Project: NoDefaultCase, Configuration: Debug Any CPU ------
1> NoDefaultCase -> C:\Users\MartinEyles\source\repos\NoDefaultCase\NoDefaultCase\bin\Debug\NoDefaultCase.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
In Visual Studio 2019, the output of the build is:
1>------ Rebuild All started: Project: NoDefaultCase, Configuration: Debug Any CPU ------
1>C:\Users\MartinEyles\source\repos\NoDefaultCase\NoDefaultCase\Program.cs(9,30,9,35): error CS0161: 'Program.GetDb()': not all code paths return a value
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Visual Studio Feedback System on 4/8/2019, 02:55 AM (8 days ago):
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Martin Eyles on 4/8/2019, 03:07 AM (8 days ago):
A github repository containing the example solution can be found at https://github.com/martineyles/NoDefaultCase This includes an archive of the example solution in the state before it was added to github (NoDefaultCase - Before Github.zip).
Martin Eyles on 4/8/2019, 05:59 AM (8 days ago):
I experience this issue in
Microsoft Visual Studio Enterprise 2019
Version 16.0.0
VisualStudio.16.Release/16.0.0+28729.10
Microsoft .NET Framework Version 4.7.03056'
It has been suggested by others in the Stack Overflow community that a preview version of Visual Studio 2019 behaves the same way as Visual Studio 2017
Martin Eyles on 4/12/2019, 05:24 AM (4 days ago):
The issue is still present in:
Microsoft Visual Studio Enterprise 2019
Version 16.0.1
VisualStudio.16.Release/16.0.1+28803.156
Microsoft .NET Framework Version 4.7.03056
Martin Eyles on 4/12/2019, 05:26 AM (4 days ago):
Stack overflow users has suggested that this does not meet the C# specification, and is likely to be either a bug or a change in the specification that hasn't yet been documented.
Martin Eyles on 4/12/2019, 05:29 AM (4 days ago):
To quote a user with very good reputation on stack overflow:
The ECMA C# 5 standard section 13.8.3 describes the reachability of the end of a switch statement:
None of these seem to be the case in your example:
So with C# 5 rules, the end point of this switch statement is not reachable, and it should compile with no problems. The draft specification in GitHub has the same text, so it doesn't look like it's changed there yet...
These are the original issue solutions:
(no solutions)
The text was updated successfully, but these errors were encountered: