Make connection between return nullable value and output nullable parameter. #3516
Replies: 7 comments
-
2 things:
|
Beta Was this translation helpful? Give feedback.
-
I have encountered it in my code when starting using nullable . I have a method which returns not null when it succeeds and sets some output parameter. There some workarounds like making everything output and return Boolean. Any workaround means rewriting code which is not a good option right now since it involves too much changes. |
Beta Was this translation helpful? Give feedback.
-
We understand that, which is why there are lots of escape hatches built into nrt. However, I'm just pointing out that after 7 months or so, this is the first request that I'm aware of for this type of attribute, and that nullable analysis as it's built today is not equipped to handle it. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately I have been busy with writing features, tests and improving stability of application for these 7 months. I should have been started porting to nullable much earlier and open this request since long time ago;) |
Beta Was this translation helpful? Give feedback.
-
No worries. In terms of feasibility, though, this request compared to your other open requests is geotagging pictures vs determining whether it's of a bird: https://xkcd.com/1425/ |
Beta Was this translation helpful? Give feedback.
-
As your function either effectively returns two nulls or two not-nulls,
could it instead return either null or a single not-null tuple (and ignore
the out variable)?
…On Sat, 30 May 2020 at 15:46, Fred Silberberg ***@***.***> wrote:
I should have been started porting to nullable much earlier and open this
request since long time ago;)
No worries. In terms of feasibility, though, this request compared to your
other open requests is geotagging pictures vs determining whether it's of a
bird: https://xkcd.com/1425/
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/csharplang/issues/3516#issuecomment-636340558>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQM74SJ2QLGSPMNNXVTRUEL3DANCNFSM4NOUVMBQ>
.
|
Beta Was this translation helpful? Give feedback.
-
As I said it is a workaround and requires code change. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Today you can specify parameter => return value direction:
It means if
output
is not null, then the return value is not null.However, it is impossible to specify the other direction: if return value is not null, then output is not null.
I suggest adding another attribute for this:
NotNullIfReturnNotNull
Beta Was this translation helpful? Give feedback.
All reactions