Thread overview
[Issue 9749] New: typeof(return) is sometimes disallowed for inner functions
Mar 18, 2013
Andrej Mitrovic
Mar 19, 2013
Andrej Mitrovic
Mar 19, 2013
Andrej Mitrovic
[Issue 9749] typeof(return) in function signature
Mar 23, 2013
David Nadlinger
Mar 24, 2013
Andrej Mitrovic
March 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749

           Summary: typeof(return) is sometimes disallowed for inner
                    functions
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2013-03-18 11:11:25 PDT ---
This is borderline between enhancement request and bug report.

This is sometimes useful when you use nested functions:


int main() {
    typeof(return) foo(typeof(return) y) {
        return y * y;
    }
    return foo(1) + foo(3);
}



DMD 2.063alpha gives:

temp.d(2): Error: typeof(return) must be inside function
temp.d(5): Error: function temp.main.foo (_error_) is not callable using
argument types (int)
temp.d(5): Error: function temp.main.foo (_error_) is not callable using
argument types (int)



Note that this code gives no errors, so all errors come from "typeof(return)
y":

int main() {
    typeof(return) foo(int y) {
        return y * y;
    }
    return foo(1) + foo(3);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |andrej.mitrovich@gmail.com
           Platform|x86                         |All
         OS/Version|Windows                     |All


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-18 11:25:10 PDT ---
Experimental pull:

https://github.com/D-Programming-Language/dmd/pull/1764

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749



--- Comment #2 from bearophile_hugs@eml.cc 2013-03-19 11:19:12 PDT ---
Thank you for your patch Andrej.

Don, from the GitHub thread:

> The enhancement request seems a bit doubtful to me, doesn't it cause confusion?

I kind of agree with Don here... Bargaining a little convenience with some potential confusion isn't so good in a programming language.

Do you want me to close this ER down?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-19 11:23:35 PDT ---
(In reply to comment #2)
> Thank you for your patch Andrej.
> 
> Don, from the GitHub thread:
> 
> > The enhancement request seems a bit doubtful to me, doesn't it cause confusion?
> 
> I kind of agree with Don here... Bargaining a little convenience with some potential confusion isn't so good in a programming language.
> 
> Do you want me to close this ER down?

We could rename it to allow these cases which are currently disallowed:

// ok, infer from return type
int a(typeof(return) intVar)
{
    return 1;
}

// ok, infer from return expression
auto b(typeof(return) intVar)
{
    return 1;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-19 11:26:29 PDT ---
(In reply to comment #3)
> // ok, infer from return expression
> auto b(typeof(return) intVar)
> {
>     return 1;
> }

Actually that one might be a bit hard to implement. But the other one might be worth doing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|typeof(return) is sometimes |typeof(return) in function
                   |disallowed for inner        |signature
                   |functions                   |


--- Comment #5 from bearophile_hugs@eml.cc 2013-03-19 12:30:22 PDT ---
(In reply to comment #4)

> But the other one might be worth doing.

It's sometimes useful to make the code more DRY.

I have renamed this issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749


David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at


--- Comment #6 from David Nadlinger <code@klickverbot.at> 2013-03-23 15:07:07 PDT ---
See the pull request discussion: I doubt that this adds enough value to make up for the amount of confusion it can cause.

bearophile, could you maybe name a few use cases where this really helps?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX
         AssignedTo|andrej.mitrovich@gmail.com  |nobody@puremagic.com


--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-23 17:44:31 PDT ---
Both of these proposals were rejected.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749



--- Comment #8 from bearophile_hugs@eml.cc 2013-03-23 18:19:47 PDT ---
(In reply to comment #7)
> Both of these proposals were rejected.

I see. Thank you for all.


> But if he can do that for the return type, he can also do it for the parameter. So the feature doesn't add much of anything.

This is not true. Specifying it once instead of twice is more DRY, and this is good.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9749



--- Comment #9 from bearophile_hugs@eml.cc 2013-03-23 18:22:06 PDT ---
(In reply to comment #6)
> could you maybe name a few use cases where this really helps?

It helps to reduce the number of times you have to state a type.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------