You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Goal is to avoid the default case when it can't happen
Describe the solution you'd like
Assuming you have a private protected constructor as only way to create an abstract class instance, it means all classes will be defined in the assembly so the compiler know all classes, then switch expression testing the type only shouldn't require default when all types are listed
Additional context
Ex:
publicabstractclassBase{privateprotectedBase(){}publicabstractstringWhatever();}publicclassFoo:Base{publicoverridestringWhatever()=>"foo";}publicclassBar:Base{publicoverridestringWhatever()=>"bar";}publicstaticclassDemo{publicstaticvoidMain(string[]args){Baseinstance=newFoo();vartest=instanceswitch{Foof=>f,Barb=>b,{}other=>other,// this is useless but required today};}}
The text was updated successfully, but these errors were encountered:
@KalleOlaviNiemitalo assuming so, the fact is a standard switch doesn't need that and the program would need to modify the switch anyway to handle the class so compiler really assume build time code and runtime code must ensure it modifies the code properly to keep it working, default case in switch expression is not in this case most of the time for previous case since you designed a closed set of classes and add one so most of the code must be rewritten at runtime with emit api anyway.
Also dotnet/csharplang#8927, which proposes marking closed class hierarchies with a dedicated keyword in the source code, rather than than inferring that from the accessibility of constructors.
Is your feature request related to a problem? Please describe.
Goal is to avoid the default case when it can't happen
Describe the solution you'd like
Assuming you have a private protected constructor as only way to create an abstract class instance, it means all classes will be defined in the assembly so the compiler know all classes, then switch expression testing the type only shouldn't require default when all types are listed
Additional context
Ex:
The text was updated successfully, but these errors were encountered: