D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8326 - std.string.format results in run-time exception
Summary: std.string.format results in run-time exception
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-30 11:19 UTC by Puneet Goel
Modified: 2013-01-02 10:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Puneet Goel 2012-06-30 11:19:22 UTC
std.string.format throws runtime exception for BigInt and for BitArray types even though writefln works fine. The run-time error says 
std.format.FormatException@std/format.d(4744): Can't convert std.bigint.BigInt to string: "string toString()" not defined

Here is a small test case:


void main()
{
  import std.stdio;
  import std.string;
  import std.bigint;
  import std.bitmanip;

  BigInt aa = 100;

  BitArray bb;
  bb.init([true, false]);

  writefln("%x", aa);
  writefln("%x", bb);
  writeln(format("%x", aa)); // throws exception
  writeln(format("%x", bb)); // throws exception
}
Comment 1 hsteoh 2012-10-27 12:14:24 UTC
Yeah std.string.format is being deprecated, because it is an inferior version of std.format. Until it is replaced by the latter, using xformat should work (xformat simply calls std.format so it will be identical to writeln & friends).
Comment 2 hsteoh 2012-10-27 12:15:25 UTC
I meant to paste the modified code:

void main()
{
  import std.stdio;
  import std.string;
  import std.bigint;
  import std.bitmanip;

  BigInt aa = 100;

  BitArray bb;
  bb.init([true, false]);

  writefln("%x", aa);
  writefln("%x", bb);
  writeln(xformat("%x", aa)); // this works
  writeln(xformat("%x", bb)); // this works
}
Comment 3 hsteoh 2013-01-02 10:13:06 UTC
This bug has been fixed in latest git head.