On Wednesday, 26 June 2013 at 18:54:17 UTC, H. S. Teoh wrote:
import std.stdio;
void main() {
size_t x = 10;
writefln("%d", x, x);
}
In a modern statically typed language I'd like such code to
give a compile-time error.
This looks like a bug to me. Please file one. :)
Not necessarily, since you might want a format string to be a
runtime variable, like when doing translations. I could live with
there being another function that does runtime though.
Things might be confusing too because of positional parameters
(%1$d). You might offer something that isn't necessarily used:
config.dateFormat = "%3$d/%2$d";
writeln(config.dateFormat, year, month, day);
Anyway, in the end I decided that naming member function
arguments after member variables is a Very Stupid Idea,
Blargh, I do it a lot. But I would be ok with the lhs of a member
when there's a parameter of the same name requiring that you call
it this.x.
How would the compiler catch such cases in general, though? I
mean, like in arbitrarily complex boolean expressions.
The Microsoft compiler warned about it, after constant folding,
working out to if(1).
I'm a little concerned that it would complain about some false
positives though, which can be quite deliberate in D, like
if(__ctfe).