Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/core/internal/dassert.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,21 @@ private string miniFormat(V)(const ref V v)
{
return "`null`";
}
else static if (__traits(compiles, { string s = v.toString(); }))
{
return v.toString();
}
// Non-const toString(), e.g. classes inheriting from Object
// toString() isn't always const, e.g. classes inheriting from Object
else static if (__traits(compiles, { string s = V.init.toString(); }))
{
return (cast() v).toString();
// Object references / struct pointers may be null
static if (is(V == class) || is(V == interface) || is(V == U*, U))
{
if (v is null)
return "`null`";
}

// Prefer const overload of toString
static if (__traits(compiles, { string s = v.toString(); }))
return v.toString();
else
return (cast() v).toString();
}
// Static arrays or slices (but not aggregates with `alias this`)
else static if (is(V : U[], U) && !isAggregateType!V)
Expand Down
3 changes: 3 additions & 0 deletions test/exceptions/src/assert_fail.d
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void testToString()()
}

test!"!="(Overloaded(), Overloaded(), "Const == Const");

Foo fnull = null;
test!"!is"(fnull, fnull, "`null` is `null`");
}


Expand Down