Skip to content

Commit 5b37317

Browse files
authored
Fix unittests of toDelegate (#10631)
As discovered by @Bolpat: <#10599 (comment)>
1 parent 488ea69 commit 5b37317

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

std/functional.d

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,16 +1886,21 @@ private template buildDelegate(F)
18861886

18871887
@safe unittest
18881888
{
1889-
static int inc(ref uint num) {
1889+
static int inc(ref int num) {
18901890
num++;
18911891
return 8675309;
18921892
}
18931893

1894-
uint myNum = 0x1337;
1895-
struct S1 { int opCall() { inc(myNum); return myNum; } }
1896-
static assert(!is(typeof(&s1.opCall) == delegate));
1894+
struct S1
1895+
{
1896+
static int myNum = 0x1337;
1897+
static int opCall() { inc(myNum); return myNum; }
1898+
}
1899+
18971900
S1 s1;
18981901
auto getvals1 = toDelegate(s1);
1902+
static assert(!is(typeof(&s1.opCall) == delegate));
1903+
static assert( is(typeof(toDelegate(s1)) == delegate));
18991904
assert(getvals1() == 0x1338);
19001905
}
19011906

@@ -1924,15 +1929,18 @@ private template buildDelegate(F)
19241929
assert(getvali() == 3);
19251930

19261931
struct S1 { int opCall() { inc(myNum); return myNum; } }
1927-
static assert(!is(typeof(&s1.opCall) == delegate));
19281932
S1 s1;
19291933
auto getvals1 = toDelegate(s1);
1934+
static assert(is(typeof(&s1.opCall) == delegate));
1935+
static assert(is(typeof(getvals1) == delegate));
1936+
assert(&s1.opCall is getvals1);
19301937
assert(getvals1() == 4);
19311938

19321939
struct S2 { static int opCall() { return 123456; } }
1933-
static assert(!is(typeof(&S2.opCall) == delegate));
19341940
S2 s2;
1935-
auto getvals2 =&S2.opCall;
1941+
auto getvals2 = toDelegate(s2);
1942+
static assert(!is(typeof(&S2.opCall) == delegate));
1943+
static assert( is(typeof(getvals2) == delegate));
19361944
assert(getvals2() == 123456);
19371945

19381946
/* test for attributes */

0 commit comments

Comments
 (0)