Bug 22796 – dual-context recursive functions seem to be broken

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-02-20T14:50:35Z
Last change time
2024-12-13T19:21:03Z
Assigned to
No Owner
Creator
Andrei Horodniceanu
Moved to GitHub: dmd#20056 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20056 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB