www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Tuple parameters for mixin templates (bug?)

1. This works:

template TFoo(T)
{
	void foo(T t)
	{
		writefln("In foo: ", t);
	}
}

template TBar(T)
{
	mixin TFoo!(T); // No mixin identifier

	void bar(T t)
	{
		writefln("In bar: ", t);
	}
}

class Test
{
	mixin TBar!(int) Bar;	
}

void main()
{
	auto test = new Test;

	test.Bar.bar(1);
	test.Bar.foo(3);
}

//---------------------------------------------

2. This crashes at compile time with Assertion failure:
'global.errors' on line 2752 in file 'template.c':

template TFoo(T ...)
{
	void foo(T t)
	{
		writefln("In foo: ", t);
	}
}

template TBar(T ...)
{
	mixin TFoo!(T);  //No mixin identifier

	void bar(T t)
	{
		writefln("In bar: ", t);
	}
}

class Test
{
	mixin TBar!(int) Bar;	
}

void main()
{
	auto test = new Test;

	test.Bar.bar(1);
	test.Bar.foo(3);
}

//-------------------------------------------

3. But this works as expected:

template TFoo(T ...)
{
	void foo(T t)
	{
		writefln("In foo: ", t);
	}
}

template TBar(T ...)
{
	mixin TFoo!(T) Foo; // Mixin identifier added.

	void bar(T t)
	{
		writefln("In bar: ", t);
	}
}

class Test
{
	mixin TBar!(int) Bar;	
}

void main()
{
	auto test = new Test;

	test.Bar.bar(1);
	test.Bar.Foo.foo(3);
}

//---------------------------------------

Must be a a bug?
Nov 10 2006