Skip to content

Commit

Permalink
fix Issue 9117 - format fails if opCast and this alias are both defin…
Browse files Browse the repository at this point in the history
…ed in an aliased struct
  • Loading branch information
9rnsr committed Dec 7, 2012
1 parent 24b7d42 commit 75064f6
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions std/format.d
Expand Up @@ -1430,6 +1430,49 @@ unittest
formatTest( S2(10), "S" );
}

// bugzilla 9117
unittest
{
static struct Frop {}

static struct Foo
{
int n = 0;
alias n this;
T opCast(T) () if (is(T == Frop))
{
return Frop();
}
string toString()
{
return "Foo";
}
}

static struct Bar
{
Foo foo;
alias foo this;
string toString()
{
return "Bar";
}
}

const(char)[] result;
void put(const char[] s){ result ~= s; }

Foo foo;
formattedWrite(&put, "%s", foo); // OK
assert(result == "Foo");

result = null;

Bar bar;
formattedWrite(&put, "%s", bar); // NG
assert(result == "Bar");
}

/**
* Floating-point values are formatted like $(D printf) does.
*/
Expand Down Expand Up @@ -2831,9 +2874,9 @@ private int getNthInt(A...)(uint index, A args)
{
return getNthInt(index - 1, args[1 .. $]);
}
static if (is(typeof(args[0]) : long) || is(typeof(arg) : ulong))
static if (isIntegral!(typeof(args[0])))
{
return to!(int)(args[0]);
return to!int(args[0]);
}
else
{
Expand Down

0 comments on commit 75064f6

Please sign in to comment.