Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Void returning Func<T> #5037

Closed
AdamSpeight2008 opened this issue Sep 5, 2015 · 2 comments
Closed

[Proposal] Void returning Func<T> #5037

AdamSpeight2008 opened this issue Sep 5, 2015 · 2 comments
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue

Comments

@AdamSpeight2008
Copy link
Contributor

Func<T> is a function that returns a T is fairly simple to understand, but is has the caveat that the T can not be Void. If T could be Void then Action<> would the equivalent to a Func<Void>

This would allow us to conceptually consider the proposed match expression (#5016) as a Func<...,T>. Permitting it to also used a statement.

...
match ( ... )
{
  |: ... => foo();
  |: ... => bar();
  |: ... => baz();
  |: => meh();  
}();
...

One could write return void;, or it could be implicitly inferred.

  => void;
  => { return void };
  => { ...;
       return void
     };
  => { ... }
@HaloFour
Copy link

HaloFour commented Sep 5, 2015

What makes this different from #234 or #166?

Func<T> is just a standard delegate, like countless others (including the other 16 Func<T, ...> delegates that ship with the framework).

Are you asking to make void/Void a possible generic type argument? Short of having a placeholder type like System.Void which would serve as a unit type I don't see how that would even approach being possible. There is only one IL body for any given generic method and it must be valid regardless of the generic type arguments, but that's certainly not possible if one of those arguments if void as that interferes with how the method could interact with the evaluation stack.

Even if you were to treat Func<T> and Action as special cases among the massive ecosystem of delegates they could not be compatible as they have different requirements of the caller. Invoking the former pushes a value onto the evaluation stack that the caller is required to at least pop in order to get equivalent semantics.

@gafter gafter closed this as completed Sep 6, 2015
@gafter gafter added the Resolution-Duplicate The described behavior is tracked in another issue label Sep 6, 2015
@gafter
Copy link
Member

gafter commented Sep 6, 2015

Duplicate of #234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

3 participants