Comment #0 by a.horodniceanu — 2022-02-20T14:50:35Z
-------------------
struct T {
void rec (alias fun) (uint n) {
if (n == 0)
return;
fun();
rec!fun(n - 1);
}
}
int *b_ptr;
void main () {
T a;
int b;
b_ptr = &b;
void someDelegate () {
assert(&b is b_ptr);
}
a.rec!someDelegate(4);
}
-------------------
This code compiles with the warning that:
------
weird.d(2): Deprecation: function `weird.main.rec!(someDelegate).rec` function requires a dual-context, which is deprecated
weird.d(21): instantiated from here: `rec!(someDelegate)`
------
And when run, it crashes the second time that `T.rec` is called.
I did not experience this behaviour when I moved the .rec method to global scope. More interestingly, if we had 2 methods calling eachother, the program doesn't crash as well:
-------------------
struct T {
// These 2 don't seem to crash
void rec1 (alias fun) (uint n) {
if (n == 0)
return;
fun();
rec2!fun(n - 1);
}
void rec2 (alias fun) (uint n) {
if (n == 0)
return;
fun();
rec1!fun(n - 1);
}
}
-------------------
`dmd --version` output:
------
DMD64 D Compiler v2.096.1
Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright
------
Comment #1 by robert.schadek — 2024-12-13T19:21:03Z