mixin template silently `override` without even a warning message!
mw
mingwu at gmail.com
Sun Oct 9 07:10:57 UTC 2022
Hi,
I just found another problem:
```
import std;
template Foo() {
void foo() {writeln("F");}
void bar() {foo();} // fixed to Foo.foo()
}
class A {
mixin Foo;
void foo() {writeln("A");} // I accidentally added this new
name-clashed method
}
void main() {
A a = new A();
a.bar(); // print F
a.foo(); // print A
}
```
1) class A ends with two methods `foo()` with the same signature!
2) whether the foo() in bar() should be fixed to Foo.foo()
(non-virtual) is debatable (I can see the reason on both sides).
3) BUT, the compiler should at least issue a warning message, so
the programmer is aware of this name clash. Even when a sub-class
override a super-class virtual method, the compiler enforces the
user to add `override` keyword, but why not in this case?
Has this problem be discussed before? and what's the conclusion?
More information about the Digitalmars-d
mailing list