Replies: 1 comment
-
This might be the most moved issue on GitHub 🤣 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@jcouv commented on Fri Apr 21 2017
@niemyjski commented on Fri Apr 21 2017
I get that this is a weird use case, but it's something the compiler allows me to do and I was even prompted by autocomplete to make my ValueTuple (a struct) nullable...
I was playing around with value tuples and in some cases I needed to return a null value (to say I can't handle it via a plugin). It was at this point autocomplete told me to make it nullable and did so for me. Granted this is the exact point in time, I should have created a class for this... But I was like ooh I can still have the pretty syntax and it works... I noticed that this quickly became a nightmare once I needed to handle null. I guess I was expecting destructuring to work and make my values null (if possible, or throw an compiler error if the tuple item type didn't support it)
@niemyjski commented on Fri Apr 21 2017
cc @jcouv
@jcouv commented on Fri Apr 21 2017
@VSadov The last error (
CS1612
) surprised me. Does it make any sense to you? If not, I'll investigate.@svick commented on Fri Apr 21 2017
@jcouv I think it's expected that if a property returns a value type, you can't modify the returned temporary value directly (because any changes would be lost).
@svick commented on Fri Apr 21 2017
I don't think that would be a good idea. If you want to return a tuple that contains
null
s, you can:But you decided to not do this and instead use nullable type. I think the compiler shouldn't ignore you made that decision.
@niemyjski commented on Fri Apr 21 2017
@svick doh, I didn't even think of that... I just did return null not thinking (and was prompted to make it nullable) and then everything hit the fan lol
@dasMulli commented on Fri Apr 21 2017
Two workarounds:
Use
??
:var (subject, data) = GetData() ?? (null, null);
Create an extension method for
ValueTuple<T1,T1>?
:While (2) seems tempting, using
default(T1)
would mean0
for ints for example so I feel this shouldn't be included in the NuGet. (Or maybe with some generic constraints)@gafter commented on Fri Apr 21 2017
If I understand correctly, I think this is by design.
Beta Was this translation helpful? Give feedback.
All reactions