Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit fa285ee

Browse files
authored
Merge pull request #2764 from RazvanN7/Issue_3831
Fix Issue 3831 - writeln of a delegate typeid merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 89288a4 + d593fac commit fa285ee

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/object.d

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,20 @@ class TypeInfo_Delegate : TypeInfo
15341534
{
15351535
override string toString() const
15361536
{
1537-
return cast(string)(next.toString() ~ " delegate()");
1537+
import core.demangle : demangleType;
1538+
1539+
alias SafeDemangleFunctionType = char[] function (const(char)[] buf, char[] dst = null) @safe nothrow pure;
1540+
SafeDemangleFunctionType demangle = ( () @trusted => cast(SafeDemangleFunctionType)(&demangleType) ) ();
1541+
1542+
return (() @trusted => cast(string)(demangle(deco))) ();
1543+
}
1544+
1545+
unittest
1546+
{
1547+
double sqr(double x) { return x * x; }
1548+
assert(typeid(typeof(&sqr)).toString() == "double delegate(double) pure nothrow @nogc @safe");
1549+
int g;
1550+
assert(typeid(typeof((int a, int b) => a + b + g)).toString() == "int delegate(int, int) pure nothrow @nogc @safe");
15381551
}
15391552

15401553
override bool opEquals(Object o)

0 commit comments

Comments
 (0)