Bug 7780 – Template mixin'd members do not properly overload
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-25T15:21:00Z
Last change time
2013-07-16T23:58:10Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
simen.kjaras
Comments
Comment #0 by simen.kjaras — 2012-03-25T15:21:31Z
mixin template A( ) {
template C( int n : 0 ) {
int C = 0;
}
}
mixin template B( ) {
template C( int n : 1 ) {
int C = 1;
}
}
class Foo {
mixin A!( );
mixin B!( );
}
void main( ) {
assert( Foo.C!0 == 0 );
}
foo.d(19): Error: __overloadset isn't a template
Or (without the wrapping class):
foo.d(17): Error: template instance C!(0) ambiguous template declaration foo.B!().C(int n : 1) and foo.A!().C(int n : 0)
The two versions of C here introduced could clearly coexist and be referred to as Foo.C!0 and Foo.C!1.
Comment #1 by degener_trash — 2012-05-19T01:16:59Z
Also trivial methods hides mixin overloads:
static struct A {
// to generate a lot of repeating overloads
// mixin will be good
mixin template _bind(T, string S) {
string bind(T var) { return S; }
}
mixin _bind!(short, "Short");
mixin _bind!(int, "Int");
string bind(long var) { return "Long"; }
string bind(double var) { return "Double"; }
}
A a;
short s; int i; long l; double d;
string all = a.bind(s) ~ a.bind(i) ~ a.bind(l) ~ a.bind(d);
assert(all == "ShortIntLongDouble"); // fail with "LongLongLongDouble"
// mixin scopes is invisible for bind() overloading
Comment #2 by simen.kjaras — 2012-05-19T03:01:00Z
(In reply to comment #1)
> Also trivial methods hides mixin overloads:
>
[snip]
Actually, that is quite clearly described under template mixins[1]:
"If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one"
I agree it would be nice to have a way to not have them override, but I can absolutely see why one might want that rule.
[1]: http://dlang.org/template-mixin.html
Comment #3 by k.hara.pg — 2013-07-04T05:55:37Z
(In reply to comment #0)
[snip]
>
> foo.d(19): Error: __overloadset isn't a template
>
> Or (without the wrapping class):
>
> foo.d(17): Error: template instance C!(0) ambiguous template declaration
> foo.B!().C(int n : 1) and foo.A!().C(int n : 0)
>
> The two versions of C here introduced could clearly coexist and be referred to
> as Foo.C!0 and Foo.C!1.
https://github.com/D-Programming-Language/dmd/pull/1660
Comment #4 by github-bugzilla — 2013-07-16T18:35:49Z