On Mon, 11 Apr 2011 16:35:39 -0400, Andrej Mitrovic <[email protected]> wrote:

There is a bug here:

import std.stdio;

void main()
{
    int index;
    writef("The index is", index);
}

Actually I found this bug in some example code: http://d.puremagic.com/issues/show_bug.cgi?id=5836

writef is missing a format specifier. But it still accepts this code.

Is it possible for writef to statically check whether there's a format specifier, assuming there's multiple arguments and the first argument is a string literal?

I realize runtime checks would be out of the question, but I'm looking for compile-time checks when it's possible to do so.

Why would runtime checks be out of the question? You are already parsing the string at runtime, why can't it say "hey, I processed the whole format string, but I have these arguments left over"? Would be a simple if statement...

A compile-time check would be nice, but you'd have to pass it as a compile-time argument (i.e. a template parameter), which would be not-so-nice.

What would be nice is if the compiler could check when you give it a string literal, and resort to runtime checks when it was a variable. I don't think that's possible, however.

-Steve

Reply via email to