www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Template method bug bouquet

reply Victor Nakoryakov <nail-mail mail.ru> writes:
Hello all.

 module core;
 
 class MyClass
 {
 	template foo(T)
 	{
 		T[] foo()
 		{
 			T[] tt;
 			return tt;
 		}
 	}
 }
 
 class Container
 {
 	this()
 	{
 		_element = new MyClass();
 	}
 
 	MyClass element()
 	{
 		return _element;
 	}
 	
 	private MyClass _element;
 }
 
 int main(char[][] args)
 {
 	Container container = new Container();
 	MyClass myclass = new MyClass();
 	
 	assert( container.element.foo!(MyClass).length == 0 ); // (*)
 	assert( myclass.foo!(MyClass).length == 0 || myclass.foo!(MyClass)[0] is
myclass ); // (**)
 
 	return 0;
 }

Compilation gives: D:\proj\dtest>dmd -unittest -debug core.d core.d(38): template foo!(MyClass) is not a member of container.element no property 'length' for type 'int' core.d(39): undefined identifier myclass dotexp template instance foo!(MyClass ).length core.d(39): void has no value core.d(39): incompatible types for ((myclass dotexp template instance foo!(MyClass ).length) == (0)): 'void' and 'int' + compiler crash. Commenting line (*) leads to successful compilation, link and run Commenting second condition in line (**) (that after || ) prevents compiler crash. Replacing line (*) with # MyClass e = container.element; # assert( e.foo!(MyClass).length == 0 ); leads to successful compilation, link and run. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Jul 07 2005
parent =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Victor Nakoryakov schrieb:
 Hello all.
 
 module core;

 class MyClass
 {
     template foo(T)
     {
         T[] foo()
         {
             T[] tt;
             return tt;
         }
     }
 }

 class Container
 {
     this()
     {
         _element = new MyClass();
     }

     MyClass element()
     {
         return _element;
     }
     
     private MyClass _element;
 }

 int main(char[][] args)
 {
     Container container = new Container();
     MyClass myclass = new MyClass();
     
     assert( container.element.foo!(MyClass).length == 0 ); // (*)
     assert( myclass.foo!(MyClass).length == 0 ||
 myclass.foo!(MyClass)[0] is myclass ); // (**)

     return 0;
 }

Compilation gives: D:\proj\dtest>dmd -unittest -debug core.d core.d(38): template foo!(MyClass) is not a member of container.element no property 'length' for type 'int' core.d(39): undefined identifier myclass dotexp template instance foo!(MyClass ).length core.d(39): void has no value core.d(39): incompatible types for ((myclass dotexp template instance foo!(MyClass ).length) == (0)): 'void' and 'int' + compiler crash. Commenting line (*) leads to successful compilation, link and run Commenting second condition in line (**) (that after || ) prevents compiler crash. Replacing line (*) with # MyClass e = container.element; # assert( e.foo!(MyClass).length == 0 ); leads to successful compilation, link and run.

gdb / dmd-0.l29: #0 0x0809b6d8 in ArrayExp::semantic(Scope*) () #1 0x0809820a in BinExp::semantic(Scope*) () #2 0x080982cd in BinExp::semanticp(Scope*) () #3 0x0809eb8c in IdentityExp::semantic(Scope*) () #4 0x0809e34b in OrOrExp::semantic(Scope*) () #5 0x08098108 in UnaExp::semantic(Scope*) () #6 0x08098512 in AssertExp::semantic(Scope*) () #7 0x080d4572 in ExpStatement::semantic(Scope*) () #8 0x080d4983 in CompoundStatement::semantic(Scope*) () #9 0x080a0dbf in FuncDeclaration::semantic3(Scope*) () #10 0x080bc5e8 in Module::semantic3() () #11 0x080ba8f3 in main () #12 0x400f2c57 in __libc_start_main () from /lib/i686/libc.so.6 Added to DStress as http://dstress.kuehne.cn/run/b/bug_expression_4275_A.d http://dstress.kuehne.cn/run/b/bug_expression_4275_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDEYDl3w+/yD4P9tIRAgihAJ9kTuO3MPBIvZcxgAvIwipy6V9/XwCfSqss 7BSLmOSiwa7wUuVM6GzGyg4= =FMoF -----END PGP SIGNATURE-----
Aug 28 2005