The assertion fails when you compile the code with -inline. void main() { static auto makeS2(int x) { struct S2 { int n; int get() { return x; } // x will be a cloaure variable } return S2(x); } auto s2a = makeS2(1); // Fails, because inlined get() returns incorrect value assert(s2a.get() == 1); } The parameter 'x' of makeS2 function is a closure variable. It's offset is calculated in makeS2->toObjFile(). But with -inline, the get function call is expanded in main(). Then the inlined code will access x via the hidden field of s2a, by using 0 offset (wrong). To fix the problem, we need to determine all offsets of closure vars in front-end.
https://github.com/D-Programming-Language/dmd/pull/4765
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6f0f6db976af6fe6ebbaba05b968a354a58994ad fix Issue 14730 - Wrong closure var access with -inline https://github.com/D-Programming-Language/dmd/commit/2d0bcf1fbd4db3d4a96c5413cdda292c0f151ed4 Merge pull request #4765 from 9rnsr/fix14730 Issue 14730 - Wrong closure var access with -inline