Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 3836 - [TDPL] obligatory override attribute #462

Merged
merged 1 commit into from over 1 year ago

3 participants

Daniel Murphy Andrei Alexandrescu Hara Kenji
Daniel Murphy
Collaborator

Move requiring the override attribute to the next stage, from warning to deprecated.

http://d.puremagic.com/issues/show_bug.cgi?id=3836

Daniel Murphy yebblies referenced this pull request
Merged

Deprecations #697

Daniel Murphy Fix Issue 3836 - [TDPL] obligatory override attribute
Move requiring the override attribute to the next stage, from warning to deprecated.
d6d3ed2
Andrei Alexandrescu
Owner

This is a must and we need to merge ASAP. Required override is proven and has been adopted by modern OOP languages. Even the older ones such as C++ and Java have adopted notation for it.

I won't actually commit this as I'm not familiar with assessing the quality of implementation, but someone on the core team please do the honors. Thanks!

Hara Kenji
Collaborator

LGTM so this is a simple change to an error from a warning.

Hara Kenji 9rnsr merged commit 2625839 into from
Hara Kenji 9rnsr closed this
Hara Kenji
Collaborator

Merged.

Daniel Murphy
Collaborator

After 11 months! @andralex @9rnsr Thanks for getting things moving.

Brad Roberts braddr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Daniel Murphy yebblies deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 21, 2012
Daniel Murphy Fix Issue 3836 - [TDPL] obligatory override attribute
Move requiring the override attribute to the next stage, from warning to deprecated.
d6d3ed2
This page is out of date. Refresh to see the latest.
4  src/func.c
@@ -484,8 +484,8 @@ void FuncDeclaration::semantic(Scope *sc)
484 484
 
485 485
                 doesoverride = TRUE;
486 486
 #if DMDV2
487  
-                if (!isOverride())
488  
-                    warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
  487
+                if (!isOverride() && !global.params.useDeprecated)
  488
+                    ::error(loc, "overriding base class function without using override attribute is deprecated (%s overrides %s)", toPrettyChars(), fdv->toPrettyChars());
489 489
 #endif
490 490
 
491 491
                 FuncDeclaration *fdc = ((Dsymbol *)cd->vtbl.data[vi])->isFuncDeclaration();
9  test/compilable/deprecate2.d
@@ -16,3 +16,12 @@ float distance(point2 a, point2 b)
16 16
   d[0] = b[0] - a[0]; // if I comment out this line it won't crash
17 17
   return 0.0f;
18 18
 }
  19
+
  20
+class A3836
  21
+{
  22
+    void fun() {}
  23
+}
  24
+class B3836 : A3836
  25
+{
  26
+    void fun() {}
  27
+}
8  test/compilable/interpret3.d
@@ -3327,11 +3327,11 @@ class SomeClass : TheBase, SomeInterface
3327 3327
     int fab;
3328 3328
     int a = 17;
3329 3329
     int b = 23;
3330  
-    int foo() { return gab + a; }
3331  
-    float bar(char c) { return 2.6; }
  3330
+    override int foo() { return gab + a; }
  3331
+    override float bar(char c) { return 2.6; }
3332 3332
     int something() { return 0; }
3333  
-    int daz() { return 0; }
3334  
-    int baz() { return 0; }
  3333
+    override int daz() { return 0; }
  3334
+    override int baz() { return 0; }
3335 3335
 }
3336 3336
 
3337 3337
 class Unrelated : TheBase {
2  test/runnable/testcontracts.d
@@ -365,7 +365,7 @@ class P7699
365 365
 }
366 366
 class D7699 : P7699
367 367
 {
368  
-    void f(int n) in { } body { }
  368
+    override void f(int n) in { } body { }
369 369
 }
370 370
 
371 371
 /*******************************************/
2  test/runnable/traits.d
@@ -696,7 +696,7 @@ class EE
696 696
 
697 697
 class FF : EE
698 698
 {
699  
-    final int YYY() { return 4; }
  699
+    final override int YYY() { return 4; }
700 700
 }
701 701
 
702 702
 static assert(__traits(isVirtualMethod, FF.YYY));
16  test/runnable/xtest46.d
@@ -3056,11 +3056,11 @@ void test3559()
3056 3056
 
3057 3057
     static class B : A
3058 3058
     {
3059  
-        int foo(float a) { return 2; }
  3059
+        override int foo(float a) { return 2; }
3060 3060
         alias A.foo foo;
3061 3061
 
3062 3062
         alias A.bar bar;
3063  
-        int bar(float a) { return 2; }
  3063
+        override int bar(float a) { return 2; }
3064 3064
     }
3065 3065
 
3066 3066
     {
@@ -3427,7 +3427,7 @@ void test5554()
3427 3427
     interface I { MB foo(); }
3428 3428
     class B : A
3429 3429
     {
3430  
-        MC foo() { return null; }
  3430
+        override MC foo() { return null; }
3431 3431
     }
3432 3432
     class C : B, I
3433 3433
     {
@@ -4734,11 +4734,11 @@ class Base3282
4734 4734
 }
4735 4735
 class Derived3282 : Base3282
4736 4736
 {
4737  
-    string f()
  4737
+    override string f()
4738 4738
     {
4739 4739
         return "Derived.f()";
4740 4740
     }
4741  
-    string f() const
  4741
+    override string f() const
4742 4742
     {
4743 4743
         return "Derived.f() const";
4744 4744
     }
@@ -4764,7 +4764,7 @@ class C7534
4764 4764
 class D7534 : C7534
4765 4765
 {
4766 4766
     override int foo(){ return 2; }
4767  
-    int foo() const { return 3; }
  4767
+    override int foo() const { return 3; }
4768 4768
     // Error: D.foo multiple overrides of same function
4769 4769
 }
4770 4770
 void test7534()
@@ -4798,8 +4798,8 @@ class V7534
4798 4798
 }
4799 4799
 class W7534 : V7534
4800 4800
 {
4801  
-    Y7534 foo(){ return new Y7534(1); }
4802  
-    Y7534 foo() const { return new Y7534(2); }
  4801
+    override Y7534 foo(){ return new Y7534(1); }
  4802
+    override Y7534 foo() const { return new Y7534(2); }
4803 4803
 }
4804 4804
 
4805 4805
 void test7534cov()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.