-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
return;
in functions with explicit Void
return type
#518
Comments
Richard~
What about the current structure for must_tail which requires `return
foo()` for void tail calls?
Matt
…On Tue, May 4, 2021, 4:39 PM Richard Smith ***@***.***> wrote:
We should consider one change relative to the C++ rules for return; / return
expression;.
In C++ and in #415
<#415>, either form
can be used in a function with a Void return type. The proposed
alternative rule is:
- If the function specifies a return type (eg, fn F() -> Int { or fn
F() -> Void {), then every return statement must have an expression,
and control reaching the end of the function is a bug (without meaning to
specify here what the response to the bug is -- UB or a diagnostic or a
trap or something).
- If the function does not specify a return type (eg, fn F() {), then
every return statement (if any) must be of the form return;, and
control reaching the end of the function implicitly returns.
This makes the handling of Void uniform, removing special cases, while
still supporting both return; in the "functions that don't return a
value" case and also return expression; in a generic context even when
the return type ends up being Void.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#518>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAALOCTWC6Y2VJGWPQ2VW2TTMBLRFANCNFSM44DNEHPQ>
.
|
If we were to exactly follow the design of the Clang attribute, this would mean that function that contain a guaranteed tail call would need to be written with an explicit return type -- |
Agreed with the suggested direction. We might want to restrict further or tweak, but this is a good start.
FWIW, I would like tail calls, but would specifically prefer a different syntax. Anyways, not something we need to stress about today. |
Decision: Make the proposed change. |
We should consider one change relative to the C++ rules for
return;
/return expression;
.In C++ and in #415, either form can be used in a function with a
Void
return type. The proposed alternative rule is:fn F() -> Int {
orfn F() -> Void {
), then every return statement must have an expression, and control reaching the end of the function is a bug (without meaning to specify here what the response to the bug is -- UB or a diagnostic or a trap or something).fn F() {
), then every return statement (if any) must be of the formreturn;
, and control reaching the end of the function implicitly returns.This makes the handling of
Void
uniform, removing special cases, while still supporting bothreturn;
in the "functions that don't return a value" case and alsoreturn expression;
in a generic context even when the return type ends up beingVoid
.The text was updated successfully, but these errors were encountered: