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 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 leads to successful compilation, link and run.
gdb / dmd-0.l29: 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