Tuple parameters for mixin templates (bug?)

Max Samuha maxter at i.com.ua
Fri Nov 10 00:12:23 PST 2006


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?



More information about the Digitalmars-d-learn mailing list