Skip to content

Commit 4c4c37a

Browse files
authored
Fix #10603 - toDelegate accepts but can’t handle a templated opCall (#10602)
1 parent 8c6fca9 commit 4c4c37a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

std/functional.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,10 @@ if (isCallable!(F))
18191819
{
18201820
return toDelegate(&fp.opCall);
18211821
}
1822+
else static if (is(typeof(&fp.opCall!())))
1823+
{
1824+
return toDelegate(&fp.opCall!());
1825+
}
18221826
else
18231827
{
18241828
alias DelType = typeof(&(new DelegateFaker!(F)).doIt);
@@ -1949,6 +1953,20 @@ if (isCallable!(F))
19491953
}
19501954
}
19511955

1956+
1957+
@system unittest
1958+
{
1959+
static struct S1 { static void opCall()() { } }
1960+
static struct S2 { static T opCall(T = int)(T x) {return x; } }
1961+
1962+
S1 i1;
1963+
const dg1 = toDelegate(i1);
1964+
dg1();
1965+
1966+
S2 i2;
1967+
assert(toDelegate(i2)(0xBED) == 0xBED);
1968+
}
1969+
19521970
/**
19531971
* Passes the fields of a struct as arguments to a function.
19541972
*

0 commit comments

Comments
 (0)