www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12154] New: Address of a member function doesn't tell about this - breaks std.concurrency

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

           Summary: Address of a member function doesn't tell about this -
                    breaks std.concurrency
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: destructionator gmail.com


--- Comment #0 from Adam D. Ruppe <destructionator gmail.com> 2014-02-13
13:51:58 PST ---
http://stackoverflow.com/questions/21765885/the-this-pointer-and-message-receiving-in-d/21766122#21766122


Currently, this compiles:

class Foo {
        void bar(int) {}
}

static assert(is(typeof(&Foo.bar) == void function(int)));


But if you actually try to use it, you get a problem:

void main() {
        void function(int) fn = &Foo.bar;
        fn(10);
}
$ ./test52
Segmentation fault


Being a non-static member variable, it expects a context pointer to be passed
to it as well, but there's no indication of that in the returned type.

I think it should actually be typed void function(int, Foo); or something like
that. Otherwise, generic code that tries to look at the type,
std.concurrency.receive for example, can try to blindly use it and get runtime
crashes where i think it should be a type system error.

It also cannot be a delegate at this point because the context pointer is
unknown.


The exception is if you are already in a non-static method and refer to it:

class Foo {
        void bar(int a) {
                import std.stdio;
                writeln(a);
        }
}
class Baz : Foo {
        override void bar(int) {
                Foo.bar(1); // calls the method from the super class
        }
}


In this case, the address-of operator already yields void delegate(int a) -
which works and makes sense.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12154


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2014-02-14 09:09:19 PST
---
There is issue devoted to that funcptr property of delegate should return
function prototype for which first arguement is delegate context pointer
(probably void*). This is essentially duplicate (but test case should be
added), unfortunately I cannot find number now.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12154


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE


--- Comment #2 from yebblies <yebblies gmail.com> 2014-02-16 02:18:59 EST ---
This is issue 3720, the delegate one is issue 2672.

I'm starting to think `&Type.nonstaticfunc` should only be valid inside typeof,
and otherwise give a 'need this to access ...' error.

*** This issue has been marked as a duplicate of issue 3720 ***

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