Nullability checks and optional parameters with default value #2798
Replies: 5 comments
-
Also: if I call this method by explicitly passing var foo = new Foo<string>();
foo.Bar(default); // warning
foo.Bar(); // no warning |
Beta Was this translation helpful? Give feedback.
-
I assume this is because if Adding the |
Beta Was this translation helpful? Give feedback.
-
Yes, I thought of that, but it doesn't seem like a valid argument to me. Just because there are cases where it would be valid, doesn't mean it should be allowed. The more important argument, IMO, is that there are cases where it would not be valid, so it shouldn't be allowed. |
Beta Was this translation helpful? Give feedback.
-
Passing the same constant of default parameter should definitely provide same result if there's no overloads.
|
Beta Was this translation helpful? Give feedback.
-
See this proposal: https://github.com/dotnet/csharplang/pull/4101/files |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry if a similar issue has already been raised, but if it exists, I couldn't find it...
In the following code, with nullability enabled, shouldn't
T value = default
cause a warning?If
T
is a non-nullable reference type, thendefault
isn't a valid value for it.Even if I add a
notnull
constraint onT
, I still get no warning.A warning is emitted only if I add a
class
constraint.Beta Was this translation helpful? Give feedback.
All reactions