Jump to page: 1 2
Thread overview
[Issue 3836] New: obligatory override attribute
[Issue 3836] [TDPL] obligatory override attribute
Mar 23, 2011
Jonathan M Davis
Apr 26, 2011
Jonathan M Davis
Apr 26, 2011
Jonathan M Davis
Jun 17, 2011
yebblies
Oct 09, 2011
Walter Bright
Oct 19, 2011
yebblies
[Issue 3836] [tdpl] obligatory override attribute
Feb 29, 2012
Stewart Gordon
Sep 25, 2012
Kenji Hara
February 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3836

           Summary: obligatory override attribute
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-02-18 13:15:09 PST ---
override attribute is better to become obligatory (even when no -w is used) as in C#, to avoid mistakes like this:

import std.stdio;

class Dog {
    public static void bark() {
        writeln("woof ");
    }
}

class Basenji : Dog {
    public static void bark() {}
}

void main() {
    Dog woofer = new Dog();
    Dog nipper = new Basenji();
    woofer.bark();
    nipper.bark();
}

If the programmer knows that override is present if and only if a method override another one, then this code can't be ambiguous.

(I think in C++ the obligatory override attribute is less necessary because methods are not virtual by default, so only if you add an explicit "virtual" a method can be overriden).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 23, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com
            Summary|obligatory override         |[TDPL] obligatory override
                   |attribute                   |attribute


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-03-22 18:16:39 PDT ---
override is obligatory according to TDPL.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #2 from bearophile_hugs@eml.cc 2011-04-26 04:26:24 PDT ---
How do you compile this with "-w" (warnings on) (reduced from code by Benjamin
Thaut)?


class Foo(T, R...) : Foo!R {
    void bar() {
        super.bar();
    }
}
class Foo(T){
    void bar() {}
}
void main() {
    new Foo!(int, float)();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-04-26 09:31:26 PDT ---
You add override to the subclass' bar function's signature.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #4 from bearophile_hugs@eml.cc 2011-04-26 10:10:36 PDT ---
(In reply to comment #3)
> You add override to the subclass' bar function's signature.

Do you want to show me the code that compiles with -w?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #5 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-04-26 10:25:50 PDT ---
class Foo(T, R...) : Foo!R {
    override void bar() {
        super.bar();
    }
}
class Foo(T){
    void bar() {}
}
void main() {
    new Foo!(int, float)();
}

I don't see what's so confusing about that. Per -w (and per TDPL) any time that you override a function, you need to put the override attribute on the version in the subclass.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #6 from bearophile_hugs@eml.cc 2011-04-26 10:27:29 PDT ---
I was about to write an answer like yours, sorry :-)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 17, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies@gmail.com


--- Comment #7 from yebblies <yebblies@gmail.com> 2011-06-17 06:05:44 PDT ---
https://github.com/D-Programming-Language/dmd/pull/136

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2011-10-09 11:18:16 PDT ---
The reason this is marked as a warning is to not break existing code without providing a long transition period for users. The next step will be to make it deprecated, and then an error.

I'll merge all the test case patches, but not the func.c change.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3836



--- Comment #9 from bearophile_hugs@eml.cc 2011-10-09 13:31:58 PDT ---
(In reply to comment #8)
> The reason this is marked as a warning is to not break existing code without providing a long transition period for users. The next step will be to make it deprecated, and then an error.
> 
> I'll merge all the test case patches, but not the func.c change.

I understand. It will take a year or more.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2