[Proposal] Conditional out keyword #8544
-
SummaryI propose to add a trueout and falseout keyword, that are out keywords, with the addition, that the compiler knows, that all trueout's exist if the function returned true and all falseout's exist if the function returned false. This will make out safer and easier to use. ExamplesTo use it simply define a function, that has to return a boolean with one or more trueout or falseout parameters.
Then you can use it like this:
It should throw a compile error in these situations, which would make it safer to use than simply out:
Each trueout parameter should effectively be exactly the same as this:
Each falseout parameter should effectively be exactly the same as this:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
What are the use cases for a feature like this? Seems like something you could accomplish with an analyzer that does some flow analysis and a custom attribute on the |
Beta Was this translation helpful? Give feedback.
-
My use case is returning either a value or returning a reason for failure to be handeled outside of the function. There are also a lot of places, where i could replace returning an optional value and then pattern matching it to a value, to make it look nicer without compromising safety. |
Beta Was this translation helpful? Give feedback.
-
Functionally the same as #8530 . This definitely won't be considered as a keyword. |
Beta Was this translation helpful? Give feedback.
Functionally the same as #8530 . This definitely won't be considered as a keyword.