www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9749] New: typeof(return) is sometimes disallowed for inner functions

reply d-bugmail puremagic.com writes:
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



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: -------
Mar 18 2013
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Mar 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749




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: -------
Mar 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749




11:23:35 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?
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: -------
Mar 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749




11:26:29 PDT ---

 // 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: -------
Mar 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
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                   |





 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: -------
Mar 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749


David Nadlinger <code klickverbot.at> changed:

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



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: -------
Mar 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Mar 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749





 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: -------
Mar 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9749





 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: -------
Mar 23 2013