import std.stdio; struct OpApply { int opApply(int delegate(int) cb) { return cb(42); } } struct Bolinha { int a; this(ref OpApply moviadao) { foreach(int b; moviadao) { this.a = b; return; } } }; void main() { import std.stdio; OpApply range; writeln(Bolinha(range).a); } The expected print result was 42. But I get a random memory garbage instead. The following minor modification in main will 'fix' the issue: void main() { import std.stdio; OpApply range; Bolinha littleBall = Bolinha(range); writeln(littleBall.a); }
Slightly reduced: ---- struct OpApply { int opApply(int delegate(int) cb) { return 0; } } struct Bolinha { int a = 0; this(int dummy) { OpApply moviadao; foreach(int b; moviadao) return; } } void main() { import std.stdio; writeln(Bolinha(0).a); } ---- Also fails on Linux and Windows (wine).
Works reliably since 2.094.1 according to run.dlang.io / local tests
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19184 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB