www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3081] New: unaryFun can't be used to get element out of struct

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

           Summary: unaryFun can't be used to get element out of struct
           Product: D
           Version: 2.030
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


import std.algorithm;

struct Foo {
    uint num;
}

void main() {
    Foo[] foos;
    auto bar = map!("a.num")(foos);
}

C:\dmd\windows\bin\..\..\src\phobos\std\functional.d(89): Error: static assert 
"Bad unary function: a.num for type Foo"

This looks like overzealous error checking, as it worked in the old Phobos and
now fails a static assert.  Probably has to do with the fact that Foo is in a
different module than std.functional.unaryFun.

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


Jarrett Billingsley <jarrett.billingsley gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om





2009-06-19 09:51:18 PDT ---
To whom it may concern: would an "I told you so" dance here be appropriate?  ;)

String mixins are cute, but we need actual macros to be able to do things like
this more generally.

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






2009-06-19 10:21:55 PDT ---

 To whom it may concern: would an "I told you so" dance here be appropriate?  ;)
 
 String mixins are cute, but we need actual macros to be able to do things like
 this more generally.
For those interested, the cause really _is_ because Foo is defined in a different module. The unaryFun template fails because ElementType.stringof yields "Foo", which isn't visible to std.functional. Even if it could compile the lambda func, the "alias typeof(mixin(testAsExpression))" line still fails because again, Foo is not accessible. That it uses ElementType.stringof also means that it will fail for just about anything other than the builtin types. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 19 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3081


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com





PDT ---
Yeah, .stringof shouldn't be used there. But we still can get to the type
through the alias. Changing the mixin string to
enum testAsExpression = "{ ElementType "~parmName~"; return ("~fun~");}()"; 
should fix the bug.

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






2009-06-20 10:13:42 PDT ---

 Yeah, .stringof shouldn't be used there. But we still can get to the type
 through the alias. Changing the mixin string to
 enum testAsExpression = "{ ElementType "~parmName~"; return ("~fun~");}()"; 
 should fix the bug.
I can confirm that does work. That being said, the amount of acrobatics that had to be performed to make the templates involved not directly refer to the type at hand is somewhat frightening. It reminds me of implementing something by using lambdas several layers deep. This stuff probably has a limit, if not in what it can do, then in the cognitive load on the programmers using it. Too bad macros were scrapped for D2, huh? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 20 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3081






PDT ---
Bad enough

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


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrei metalanguage.com
         Resolution|                            |FIXED





23:24:17 PDT ---
Fixed, will come with the next release.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3081


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com





02:57:27 PDT ---
Fixed dmd 2.031

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