-
I hope this is the right place for this type question. Assume the following method signature:
Let some inheritance or interface compliance require this method to return
However, returning Why is that? Shouldn't the compiler be aware that assigning a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
No it does not. For one thing, Note, by the way, that a similar restriction holds with Nullable Reference Types as well, albeit with a warning rather than an error. This is one thing I'm hoping can be addressed at some point so generic inference and NRTs can play together better, but it's probably not a high priority. |
Beta Was this translation helpful? Give feedback.
-
This relates to #92
|
Beta Was this translation helpful? Give feedback.
No it does not. For one thing,
Guid
andGuid?
are completely different types, and type arguments on classes and structs must be exact because they can't be co-/contravariant. Even when using reference types, you can't convert aTask<string>
to aTask<object>
, and you can't convert aTask<Guid>
to aTask<Guid?>
for the same reason.On the other hand, the statement
Guid? emtpyId = Guid.Empty;
simply uses the implicit conversions defined onNullable<T>
(which can't be used for inferring type arguments) and so doesn't produce the same error.Note, by the way, that a similar restrictio…