Le 29/11/09 14:23, Lutger a écrit :
Denis Koroskin wrote:
On Sun, 29 Nov 2009 16:02:24 +0300, Lutger<[email protected]>
*snip*
If you want to resolve the symbol at runtime I think you can get a better
error message for throwing an exception or assertion. I don't have the
svn
dmd, so this isn't tested:
void opDispatch(string name)(string file = __FILE__, int line = __LINE__)
{
if ( !dynamicDispatch(name) )
{
// line and file are default initialized from the call site:
throw new MethodMissingException(name, file, line);
}
}
IIRC, this trick only works when __FILE__ and __LINE__ are both template
arguments.
hey that's right. That means when Walter fixes the current bug with template
parameters, good compile time error messages are possible after all.
I tried:
==============================================
module main;
import std.stdio;
import std.string;
class Test
{
string foo(string name)(string file = __FILE__, int line = __LINE__)
{
return format("Call of Test.foo at %s(%d).", file, line);
}
string bar(string name, string file = __FILE__, int line = __LINE__)()
{
return format("Call of Test.bar at %s(%d).", file, line);
}
}
void main()
{
auto test = new Test;
writeln(test.foo!"something");
writeln(test.bar!"something");
}
==============================================
and the output is:
Call of Test.foo at test.d(21).
Call of Test.bar at test.d(12).