www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7534] New: Allow attribute-overloading of an overridden method

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

           Summary: Allow attribute-overloading of an overridden method
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



Also see: http://d.puremagic.com/issues/show_bug.cgi?id=3757

class C{
    void foo(){}
}
class D : C{
    override void foo(){}
    void foo()const{}
}

Currently this is illegal. Both child class methods are assumed to override the
parent class method:

Error: D.foo multiple overrides of same function 

Only the first child class method should override the parent class method and
the second child class method would introduce an additional overload on const.

Similar observations apply to shared/immutable/inout functions.

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



I assume this is what Walter meant when he said contravariance causes problem
with overloading.

Are you sure it's a good idea to have the first overload selected?  This would
mean removing it would make the second overload the overrider.  While it will
be different once omitting 'override' is an error, override does not change
semantics in any other case, it just confirms and enforces what the compiler
determines anyway.

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




The idea is that code like this would be allowed too:

class C{
    void foo(){}
}

class D : C {
    alias C.foo foo;  // inherit from super class
    void foo()const{} // additional overload
}

I agree that implementing this requires making omission of override an error.

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




NVM, that would break code like the following:

class C{
    void foo(){writeln(1);}
    void foo()immutable{writeln(2);}
}

class D : C {
    alias C.foo foo;
    void foo()const{writeln(3);} // currently overrides 2
}

I don't know if it is worth the effort.

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




Heh, that last example should either override both or be an ambiguity error.

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


deadalnix <deadalnix gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |deadalnix gmail.com



As I explained somewhere in the news group, the current behavior is
inconsistent.

We have to choose is const is a characteristic of the method or of its
arguments.

If it is a characteristic of its argument (the hidden argument this), then
const and non const method are 2 different methods, and shouldn't override each
other.

If this is a characteristic of the method, then we shouldn't be able to define
both const and non const version of the same method, just like we cannot define
both pure and impure version of a same function.

This problem is closely related to the return type const qualifier one, both
are symptoms of the same misconception in D spec.

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




I think this is almost same as issue 3757, and I think additional overload in
derived class is useful and should work.

Example:

// after fixing object const correctness (bug 1824)
class Object {
    bool opEquals(const Object o);
    //...
}
class C {
    alias super.opEquals opEquals;

    // additional overload for mutable object equality
    override bool opEquals(Object o) {
        // special processing, e.g. caching
        return super.opEquals(o);
    }
}

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



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

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





 I think this is almost same as issue 3757
Sorry, the original issue is bug 3282, and bug 3757 depended on it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 03 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7534




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

https://github.com/D-Programming-Language/dmd/commit/12885a6cc408bfca83a89b99030697a187860781


Issue 7534 - Allow attribute-overloading of an overridden method

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


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
This compiles on 2.059

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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