Bug 1225 – Super Class method hides the global template from mixin
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-05-09T10:04:51Z
Last change time
2019-07-12T11:28:53Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
david
Comments
Comment #0 by davidl — 2007-05-09T10:04:51Z
import std.stdio;
template dup(T){
T dup(){
auto c=new T;
foreach(i,x;T.tupleof)
{
c.tupleof[i]=x;
writefln(`tupleof `,i);
}
return c;
}
}
class baseclass
{
mixin dup!(baseclass);
void method(){printf("a.method\n");}
}
class deriveclass:baseclass
{
mixin dup!(deriveclass);
int j;
void method(){printf("b.method\n");}
}
void main()
{
deriveclass mybinstance = new deriveclass;
mybinstance.dup;
}
compiler complains:
testclass.d(21): mixin dup isn't a template
Comment #1 by davidl — 2007-09-15T09:22:44Z
This illustrate the bug a little more clearly, and also fix some issues of the original code.
import std.stdio;
template dup(T){
T dup(){
auto c=new T;
foreach(i,x;this.tupleof)
{
c.tupleof[i]=x;
writefln(`tupleof `,x);
}
return c;
}
}
class baseclass
{
// mixin dup!(baseclass); // comment this , the dup won't be hidden anymore in the derive class
void method(){printf("a.method\n");}
}
class deriveclass:baseclass
{
mixin dup!(deriveclass);
int j;
float i;
void method(){printf("b.method\n");}
this()
{
i=34;
j=10;
}
}
void main()
{
deriveclass mybinstance = new deriveclass;
mybinstance.dup();
}
Comment #2 by davidl — 2007-09-23T03:27:30Z
*** Bug 1527 has been marked as a duplicate of this bug. ***
Comment #3 by razvan.nitu1305 — 2019-07-12T11:28:53Z
I don't think that this is actually a bug. You can specify that you want the outer scope symbol by using in this line in the child class (with the mixin in the parent class uncommented):
mixin .dup!(deriveclass);
But then you will end up with an error stating you forgot to use the override keyword:
Error: cannot implicitly override base class method test.baseclass.dup!(baseclass).dup with test.deriveclass.dup!(deriveclass).dup; add override attribute
This is the correct, documented behavior.
Closing as invalid. Please reopen if I am missing something.