http://d.puremagic.com/issues/show_bug.cgi?id=10489
Summary: Orphan format arguments exception/error for writeln
unless they are
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from [email protected] 2013-06-27 12:20:04 PDT ---
In DMD 2.064alpha this program compiles and runs with no errors, warnings or
run-time exceptions:
import std.stdio;
void main() {
writefln("%d %d", 1, 2, 3);
}
While this gives a run-time exception:
import std.string;
void main() {
format("%d %d", 1, 2, 3);
}
std.format.FormatException@...\dmd2\src\phobos\std\string.d(2346): Orphan
format arguments: args[2..3]
To catch some programmer mistakes I suggest to turn this into an
exception/error:
writefln("%d %d", 1, 2, 3);
But as stated by Andrei Alexandrescu:
http://forum.dlang.org/post/[email protected]
> The only point I'd negotiate would be to not throw with positional
> arguments, and throw with sequential arguments. All code that cares uses
> positional specifiers anyway.
So according to Andrei this should be accepted:
import std.stdio;
void main() {
writefln("%2$s %1$s", 1, 2, 3);
}
Currently this is accepted (and it prints "A B10"), but I think it should be
not accepted:
import std.stdio;
void main() {
writefln("A%2$s B%1$s", 10);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------