www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8809] New: Cannot statically bind to base class method overridden by derived class

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx



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: -------
Oct 12 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8809


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid



https://github.com/D-Programming-Language/dmd/pull/1181

And, this is also a problem in website.

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




Commit pushed to master at
https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/946692fbad211e84207d41da392a1f60aac9fb65
Add documentation for issue 8809

This language feature has not been clearly documented.

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/364bcddf80daf3fcf82237276f0d898cc68d91a2
fix Issue 8809 - Cannot statically bind to base class method overridden by
derived class

Collect DotType resolution code to TypeClass::dotExp

obj.Type.foo() calls Type.foo statically.
In the non-static member function, Type.foo() is implicitly translated to
this.Type.foo(), and same as well.

https://github.com/D-Programming-Language/dmd/commit/4c11aea5ddd866e1c86d10bdfb4d0acb8469b611


Issue 8809 - Cannot statically bind to base class method overridden by derived
class

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com
            Version|D2                          |D1
            Summary|Cannot statically bind to   |(D1 Only) Cannot statically
                   |base class method           |bind to base class method
                   |overridden by derived class |overridden by derived class



Fixed D2

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