When overriding a function of a base class @disable does not cause compile time errors when called. class A { @disable override equals_t opEquals(Object other) { return false; } } void main() { auto a = new A(); auto b = new A(); if(a == b) assert(0); }
This isn't actually possible. What I would suggest is the compiler failing to compile your class instead, because you can't disable a base function. If for example, you have a function like this: bool foo(Object o1, Object o2) {...} Then would it be safe to assume that you could pass both a and b to foo? If so, then isn't it possible for foo to call o1 == o2? And how could the compiler possibly statically disable this? I'm going to mark it as invalid, and if you think you'd rather have the behavior where @disable doesn't compile on overridden functions, then you can reopen with that description.
(In reply to comment #1) > This isn't actually possible. What I would suggest is the compiler failing to > compile your class instead, because you can't disable a base function. I agree. Where possible a good compiler has to statically disallow impossible code :-)
Added a note to bug 3934
class A { void hello() { } } class B : A { @disable override void hello() { } } void main() { auto a = new A(); A b = new B(); b.hello(); } The compiler should not compile the class saying something to the effect of: Can not disable method hello in base class A from B. Or another suggestion "Cannot @disable overriding function hello in B" Note that I think the code below should still compile: class A { @disable void hello() { } } class B : A { override void hello() { } } void main() { auto a = new A(); B b = new B(); b.hello(); }
*** This issue has been marked as a duplicate of issue 6760 ***