www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Interfaces + mixins => problem

reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
IMHO the following code should either fail to compile or produce a 
meaningful result:

----
import std.stdio;


interface Foo {
	template FooImpl() {
		void func();
	}
	mixin FooImpl foo;
}


interface Bar {
	template BarImpl() {
		void func();
	}
	mixin BarImpl bar;
}


class Baz : Foo, Bar {
	static template FooImpl() {
		void func() {
			writefln("FooImpl !");
		}
	}
	mixin FooImpl foo;
	
	
	static template BarImpl() {
		void func() {
			writefln("BarImpl !");
		}
	}
	mixin BarImpl bar;
}


void main() {
	Baz b = new Baz;
	Foo f = b;
	Bar r = b;

	f.func();
	r.func();
}
----


When ran, it prints:
FooImpl !
FooImpl !

It would be really great if it outputed:
FooImpl !
BarImpl !


If that's a problem, id rather it didn't compile at all...
Thanks :)

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O 
!M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y
------END GEEK CODE BLOCK------

Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
May 02 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tom S schrieb am 2006-05-02:
 IMHO the following code should either fail to compile or produce a 
 meaningful result:

 ----
 import std.stdio;


 interface Foo {
 	template FooImpl() {
 		void func();
 	}
 	mixin FooImpl foo;
 }


 interface Bar {
 	template BarImpl() {
 		void func();
 	}
 	mixin BarImpl bar;
 }


 class Baz : Foo, Bar {
 	static template FooImpl() {
 		void func() {
 			writefln("FooImpl !");
 		}
 	}
 	mixin FooImpl foo;
 	
 	
 	static template BarImpl() {
 		void func() {
 			writefln("BarImpl !");
 		}
 	}
 	mixin BarImpl bar;
 }


 void main() {
 	Baz b = new Baz;
 	Foo f = b;
 	Bar r = b;

 	f.func();
 	r.func();
 }
 ----


 When ran, it prints:
 FooImpl !
 FooImpl !

 It would be really great if it outputed:
 FooImpl !
 BarImpl !


 If that's a problem, id rather it didn't compile at all...
 Thanks :)

Baz should fail to compile:
 If two different mixins are put in the same scope, and each define a
 declaration with the same name, there is an ambiguity error when the
 declaration is referenced.

Added to DStress as http://dstress.kuehne.cn/nocompile/m/mixin_22_A.d http://dstress.kuehne.cn/nocompile/m/mixin_22_B.d http://dstress.kuehne.cn/nocompile/m/mixin_22_C.d http://dstress.kuehne.cn/nocompile/m/mixin_22_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEcipq3w+/yD4P9tIRAqSHAKCcHnbOPhUIX4QC+KwCyvpAUJnK/gCggTzf PqwV/tWwmr5KXtwonp2c3To= =Sas4 -----END PGP SIGNATURE-----
May 22 2006