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.