www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3282] New: The overload and override issue of const/immutable member functions

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

           Summary: The overload and override issue of const/immutable
                    member functions
           Product: D
           Version: 2.031
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rayerd.wiz gmail.com


import std.stdio;
class Base
{
    string f()
    {
        return "Base.f()";
    }
}
class Derived : Base
{
    string f()
    {
        return "Derived.f()";
    }
    string f() const // or immutable
    {
        return "Derived.f() const";
    }
}
void main()
{
    auto x = new Base;
    writeln(x.f());
    auto y = new Derived;
    writeln(y.f());
    auto z = new const(Derived); // or immutable
    writeln(z.f()); //object.Error: Access Violation
}

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



--- Comment #1 from Haruki Shigemori <rayerd.wiz gmail.com> 2009-10-19 03:22:09
PDT ---
This problem occurs when "const" is "shared".

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


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de


--- Comment #2 from Rainer Schuetze <r.sagitario gmx.de> 2010-01-22 00:37:37
PST ---
This kind of works now with changeset 344. But both "f()" and "f() const"
overload "f()" in the base class, and the last one wins. I think dmd should
either issue an error or add another entry to the vtbl for the non-exact but
covariant match.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3282



--- Comment #3 from Haruki Shigemori <rayerd.wiz gmail.com> 2010-01-30 23:34:40
PST ---
This problem's characteristics changed at dmd2.040.

import std.stdio;
class Base
{
    string f()
    {
        return "Base.f()";
    }
}
class Derived : Base
{
    string f()
    {
        return "Derived.f()";
    }
    string f() immutable
    {
        return "Derived.f() immutable";
    }
    string f() shared
    {
        return "Derived.f() shared";
    }
}
void main()
{
    auto x = new Base;
    writeln(x.f());
    auto y = new Derived;
    writeln(y.f());
    auto z = new immutable(Derived);
        //main.d(15): Error: function main.Derived.f of type immutable string()
overrides but is not covariant with main.Base.f of type string()
    writeln(z.f());
    auto w = new shared(Derived);
        //main.d(19): Error: function main.Derived.f of type shared string()
overrides but is not covariant with main.Base.f of type string()
    writeln(w.f());
}

Are both errors correctly?
I expected that z.f() calls "Derived.f() immutable" and w.f() calls
"Derived.f() shared".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2010