Skip to content

Commit

Permalink
Fix dlang#10603 - toDelegate accepts but can’t handle a templated `…
Browse files Browse the repository at this point in the history
…opCall` (dlang#10602)
  • Loading branch information
0xEAB authored Dec 30, 2024
1 parent 8c6fca9 commit 4c4c37a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions std/functional.d
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,10 @@ if (isCallable!(F))
{
return toDelegate(&fp.opCall);
}
else static if (is(typeof(&fp.opCall!())))
{
return toDelegate(&fp.opCall!());
}
else
{
alias DelType = typeof(&(new DelegateFaker!(F)).doIt);
Expand Down Expand Up @@ -1949,6 +1953,20 @@ if (isCallable!(F))
}
}


@system unittest
{
static struct S1 { static void opCall()() { } }
static struct S2 { static T opCall(T = int)(T x) {return x; } }

S1 i1;
const dg1 = toDelegate(i1);
dg1();

S2 i2;
assert(toDelegate(i2)(0xBED) == 0xBED);
}

/**
* Passes the fields of a struct as arguments to a function.
*
Expand Down

0 comments on commit 4c4c37a

Please sign in to comment.