Replies: 13 comments
-
This makes sense to me. Someone else may be calling the method and may not have validated that the props are non-null. Now, it's an open question if IDE shuld then add the null checks in for you. |
Beta Was this translation helpful? Give feedback.
-
THis is probably the #1 case i need to use the |
Beta Was this translation helpful? Give feedback.
-
What argument coudl not be trivially boxed into 'object'? |
Beta Was this translation helpful? Give feedback.
-
Does I'd rather autoinject it everywhere via a compiler switch than scream! in! every! public! method!, |
Beta Was this translation helpful? Give feedback.
-
Why is "argument" term even used here? Whatever you are switching on is an "expression" isn't it? https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch
|
Beta Was this translation helpful? Give feedback.
-
If NRT affects switch exhaustiveness warnings (dotnet/roslyn#30597), why we couldn't use |
Beta Was this translation helpful? Give feedback.
-
Currently (and I assume this will be the case when v8 ships), pattern matching on enums will always complain that the switch expression is not exhaustive. For example, if I do the following: public enum FooBar { Foo, Bar }
...
var x = FooBar.Foo;
var y = x switch {
FooBar.Foo => 1,
FooBar.Bar => 2
}; it gives me the warning, Since the new exception,
But since that exception is going to be introduced, it makes sense for me to use it in my default case: public enum FooBar { Foo, Bar }
...
var x = FooBar.Foo;
var y = x switch {
FooBar.Foo => 1,
FooBar.Bar => 2,
var e => throw new MatchFailureException(e.ToString())
}; So now, I'm explicitly duplicating what the compiler would implicitly do for me just to suppress a warning. I don't like disabling warnings and would be loathe to do so here, as that exhaustiveness check would make sense elsewhere. But I don't want to have to write duplicate code just to work around the warning either. So is there any way in which that warning could be suppressed for enums to avoid the need to duplicate things? Tagging @gafter here in case he has a view on this. |
Beta Was this translation helpful? Give feedback.
-
Integral enums would be only one instance, I think non-exhaustive switch expressions would not be that uncommon. perhaps there should be simple syntax like switch! to suppress that warning. |
Beta Was this translation helpful? Give feedback.
-
I'm with @DavidArno on that point. Yes, technically the switch is non-exhaustive, but an enum value that doesn't match one of its elements should be considered exceptional, IMO. That said, I could see still warning if none of the enum elements equal 0 as that would be the default value: |
Beta Was this translation helpful? Give feedback.
-
Perhaps in the absence of FlagsAttribute? I think a warning could also be useful on bitwise operations and the like on non-flag enums so that we get sensible warnings/lack of warnings on both sides. Same for zero, I'd expect a warning when an "invalid" value is produced if exhaustiveness depends on it to be correct. |
Beta Was this translation helpful? Give feedback.
-
Ah, that's true. Enums can be wonky beasts. I'd still think that the most common use of enums would be non-flags with a 0 element, but I don't know if it's be worth baking that into the spec. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour, I add to what you say by suggesting that if I only match on So taking your point about |
Beta Was this translation helpful? Give feedback.
-
I don't like the base call syntax for default interface implementations. This is specially important to me, as I am a huge supporter of functors. Obviously the currently proposed syntax would interfere with functor inheritance (Imagine a math-library with mathematical functions which have some kind of inheritance relationship). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Oct 31, 2018
C# Language Design Notes for Oct 31, 2018
Nov 5, 2018
C# Language Design Notes for Nov 5, 2018
Nov 14, 2018
C# Language Design Notes for Nov 14, 2018
Beta Was this translation helpful? Give feedback.
All reactions