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: noreturn methods #12199

Closed
omariom opened this issue Jun 24, 2016 · 3 comments
Closed

Proposal: noreturn methods #12199

omariom opened this issue Jun 24, 2016 · 3 comments

Comments

@omariom
Copy link

omariom commented Jun 24, 2016

TypeScript got never type which allows to define methods that never return.
I propose similar feature for C#.

Methods "returning" noreturn type must definitely throw or call other noreturn methods.
They can't have return statements in their body nor out parameters. At callsites they should be threated by the compiler similarly to throw statements.

It will require support from CLR. and that's a good thing as CLR could take advantage of that and optimize generated code around callsites to noreturns as it does now with throws.

private noreturn LogAndFailFast()
{
     s_logger.Log(whatever_required);
     Environment.FailFast();
}

static class ThrowHelper
{
   public noreturn ThrowInvalidInputException(ObjectType type, long id)
   {
       throw new InvalidInputException(string.Format(InvalidInputFormatString, type, id));
   }
}
@omariom
Copy link
Author

omariom commented Jun 24, 2016

@mikedn I remember you talked about benefits of noreturns for codegen.

@HaloFour
Copy link

Dupe of #1226

@omariom
Copy link
Author

omariom commented Jun 24, 2016

Ouch!

@omariom omariom closed this as completed Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants