ashmind / Unbreakable

Alive, dammit!
MIT License
37 stars 9 forks source link

Non-exhaustive switch expressions should be allowed #37

Open RikkiGibson opened 3 years ago

RikkiGibson commented 3 years ago

Take a simple scenario including a non-exhaustive switch expression:

int x = 0;
_ = x switch { 1 => 2 }; // warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '0' is not covered.

It looks like the type System.Runtime.CompilerServices.SwitchExpressionException needs to be explicitly allowed by Unbreakable for this to be allowed to run on SharpLab.

https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK7wCYgNQB9YIAEAHoQLyEAMA3ALABQA+uSYQM4DuUCAxgBaEA3oQCM5AHyEATIQC+dekA

RikkiGibson commented 3 years ago

Ping :) would be happy to try and contribute the change if you could point me in the right direction.

ashmind commented 3 years ago

Thanks for reporting! Technically, you can add it to https://github.com/ashmind/Unbreakable/blob/00c637884dd90e9ee78456cd4131421d050c157c/Policy/DefaultApiPolicyFactory.cs#L483

But practically, SharpLab is no longer using Unbreakable except in fallback flows (until container flows are more stable). So your example code should already run in SharpLab, unless you hit a fallback scenario.

ashmind commented 2 years ago

Hi @RikkiGibson, just FYI this library is being deprecated (not closing any issues in case someone wants to contribute a fix years later, however unlikely that is). However this is no longer a problem for SharpLab specifically, the code should run fine.