www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4312] New: std.traits.ReturnType no longer accepts function literals

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312

           Summary: std.traits.ReturnType no longer accepts function
                    literals
           Product: D
           Version: future
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: sandford jhu.edu



std.traits.ReturnType no longer accepts function literals. Here is a simplified
test case:

void main(string[] args) {
    writeln(  (ReturnType!( function(int a){return a;} )).stringof );
    return;
}

Results in the error:

Error: function std.traits.__funcliteral1 cannot access frame of function
__funcliteral1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rsinfu gmail.com
            Version|future                      |D2
         Depends on|                            |4333, 4217
         AssignedTo|nobody puremagic.com        |rsinfu gmail.com
         OS/Version|Windows                     |All



---
The cause of this regression is bug 4333.  Bug 4217 is also related.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



14:12:31 PDT ---
I can't reproduce this on 2.053, it compiles and runs. Can you confirm?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312




I can confirm that non-nested function literals now compile. (i.e. the original
bug report) But nested function literals don't compile (DMD 2.053):

void main(string[] args) {
    int b;
    writeln(  (ReturnType!( function(int a){return a+b;} )).stringof );
}

Error: function hello.main.__funcliteral1 cannot access frame of function D
main

Not too sure if this is a separate issue or not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com




 I can confirm that non-nested function literals now compile. (i.e. the original
 bug report) But nested function literals don't compile (DMD 2.053):
 
 void main(string[] args) {
     int b;
     writeln(  (ReturnType!( function(int a){return a+b;} )).stringof );
 }
 
 Error: function hello.main.__funcliteral1 cannot access frame of function D
 main
 
 Not too sure if this is a separate issue or not.
This is expected. A function literal cannot form a closure. You need a delegate. -------------------------- void main() { int b; auto c = function(int a){return a+b;}; } -------------------------- x.d(6): Error: function x.main.__funcliteral1 cannot access frame of function D main -------------------------- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312




I'm not defining a closure. I'm defining a nested function literal. And given
that the following compiles:

void main()
{
    int b;
    int funcliteral(int a){return a+b;}
    writeln(  (ReturnType!funcliteral).stringof );
}

I would also expect 

void main(string[] args) {
    int b;
    writeln(  (ReturnType!( function(int a){return a+b;} )).stringof );
}

to work. But, as you pointed out, this isn't a problem with ReturnType anymore.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312





 I'm not defining a closure. I'm defining a nested function literal. And given
 that the following compiles:
 
 void main()
 {
     int b;
     int funcliteral(int a){return a+b;}
     writeln(  (ReturnType!funcliteral).stringof );
 }
 
That's because the '&' of that 'funcliteral' is a delegate. Try it: --------------------------------- void main() { void f() {}; static void g() {}; pragma(msg, typeof(&f)); // void delegate() pragma(msg, typeof(&g)); // void function() } --------------------------------- And the following also does not compile: --------------------------------- void main() { int b; static int func(int a) { return a+b; } } --------------------------------- x.d(6): Error: function x.main.func cannot access frame of function D main --------------------------------- See http://d-programming-language.org/expression.html#FunctionLiteral.
 I would also expect 
 
 void main(string[] args) {
     int b;
     writeln(  (ReturnType!( function(int a){return a+b;} )).stringof );
 }
 
 to work. But, as you pointed out, this isn't a problem with ReturnType anymore.
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 27 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4312


Rob Jacques <sandford jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME



Ah. Thank you. I think then that we can close this bug.

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