[Issue 8809] New: Cannot statically bind to base class method overridden by derived class
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 12 20:30:14 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8809
Summary: Cannot statically bind to base class method overridden
by derived class
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: hsteoh at quickfur.ath.cx
--- Comment #0 from hsteoh at quickfur.ath.cx 2012-10-12 20:30:12 PDT ---
class B {
struct S {
S delegate() saveImpl;
S save() { return saveImpl(); }
}
S eval() {
// BUG: B.eval doesn't statically bind to B.eval, but ends up
in C.eval, causing stack overflow
return S(() => B.eval());
// return S(() => typeof(this).eval()); // this doesn't work
either
}
}
class C : B {
override S eval() {
auto s = super.eval();
auto t = s.save; // stack overflow, 'cos B.eval binds to C.eval
return t;
}
}
void main() {
auto c = new C;
auto s = c.eval();
}
Basically, there is no way in the base class method to statically bind to the
un-overridden method; no matter what is specified (this.eval(), B.eval(),
typeof(this).eval(), etc.), it always ends up in C.eval, causing infinite
recursion when C.eval calls s.save.
One workaround is to rename B.eval to B.evalImpl, and make B.eval a wrapper
that calls B.evalImpl. Then the delegate can be made to call evalImpl directly.
But this is quite ugly, since one would have to do this for every base class
method that needs to be statically bound in this way. One would expect the
language (or compiler) should produce a static binding to B.eval when the code
explicitly asks for B.eval.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list