Replies: 9 comments
-
Now that local functions can be recursive and can forward-reference other local functions, supporting inference in this way isn't a cleanly defined problem. I don't believe we're ever likely to do it. |
Beta Was this translation helpful? Give feedback.
-
Could the compiler be made to check for those situations and allow inference of the return value where the local function isn't recursive or invoke other local functions from which these complications would arise? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@jnm2 |
Beta Was this translation helpful? Give feedback.
-
No, not without that being described in the language specification somehow. I don't think there is a clean way to do that. |
Beta Was this translation helpful? Give feedback.
-
For that matter, would it be possible to infer the entire signature, given that inference only needs to search locally? var add(a, b) => a+b;
var x = add(1, 5); |
Beta Was this translation helpful? Give feedback.
-
And then why not allow in the same block: var y = add(1.5, 2.25); It would generate two overloads for |
Beta Was this translation helpful? Give feedback.
-
how about |
Beta Was this translation helpful? Give feedback.
-
@onionhammer i like it, 'let' is being considered for local immutable references to, at #421 and #188 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When local functions were first proposed, the return type was supposed to be inferred. But the idea was complex to implement and was postponed. Expression bodied local functions will be the simplest to infer the return type. Please do this in some upcoming 7.x release. Local functions with single return statements can also be considered for inferring. Example (not that good)-
ref: dotnet/roslyn#2930 (comment)
Beta Was this translation helpful? Give feedback.
All reactions