Bug 3656 – delegate should specify 'this' decorations
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-12-28T06:34:00Z
Last change time
2015-06-09T01:27:03Z
Assigned to
nobody
Creator
schveiguy
Comments
Comment #0 by schveiguy — 2009-12-28T06:34:17Z
Note, this bug applies to 2.037, but for some reason it's not in the version list.
import std.stdio;
class A
{
void f() {}
}
void main()
{
const A a = new A;
auto g = &a.f;
writefln("%s", typeof(g).stringof);
g();
}
This outputs:
void delegate()
First, the line:
auto g = &a.f;
shouldn't compile because f cannot be called on a. However, even if f is changed to a const function, the output is still "void delegate()", it should be "void delegate() const".
This breaks const correctness without a cast, because I can call g, but not a.f.
Comment #1 by schveiguy — 2009-12-28T08:45:23Z
Note that more important than const decoration propogation is shared propogation, since the compiler should call the delegate differently.
Note also that with contravariance for delegates as identified in bug 3075 would make this a lot easier to deal with.
Comment #2 by clugdbug — 2011-03-18T23:35:58Z
This seems to be a duplicate of bug 1983
Comment #3 by schveiguy — 2011-06-12T11:28:15Z
Yes, it's a dupe. I also realize now that identifying the decorations for the this pointer makes delegates a lot less useful, so they shouldn't specify this decorations. I think even in the case where the function is shared, it's not important, the member function should handle the shared semantics properly.
*** This issue has been marked as a duplicate of issue 1983 ***