Probably related to issue 16576, if not identical (just another angle of the same issue).
Working example:
---
struct Thing
{
enum Instance = Thing();
int a = 42;
void iter()
{
import std.stdio;
writeln(this.a); // Prints "42"
}
}
void main()
{
Thing.Instance.iter;
}
---
Broken example:
---
struct Thing
{
enum Instance = Thing();
int a = 42;
void iter()
{
import std.stdio;
writeln(this.a); // Prints "0"
}
}
void main()
{
return Thing.Instance.iter; // Added 'return'
}
---
In the bad code, the frontend gives us a CallExp for:
Instance.iter()
In the good code, the frontend gives us a CallExp for:
Thing().iter()
So it looks on the surface that constfold has missed a case where it should have propagated the manifest 'Instance' into a literal 'Thing()'.
*** Issue 16576 has been marked as a duplicate of this issue. ***
Comment #3 by dlang-bot — 2021-11-12T03:24:57Z
@BorisCarvajal created dlang/dmd pull request #13290 "Fix Issue 16579 - Corrupted runtime on missed manifest constant propagation" fixing this issue:
- Fix Issue 16579 - ReturnStatement[CallExp(DotVarExp)]: Corrupted runtime on missed manifest constant propagation
A void returning statement 'return exp;' is rewritten to 'exp; return;'
but in that case an optimize() call was missing, which was just a little above.
https://github.com/dlang/dmd/pull/13290
Comment #4 by dlang-bot — 2021-11-13T03:36:46Z
dlang/dmd pull request #13290 "Fix Issue 16579 - Corrupted runtime on missed manifest constant propagation" was merged into stable:
- 07fac3df19f026a7d04c59177287e6434981bfb0 by Boris Carvajal:
Fix Issue 16579 - ReturnStatement[CallExp(DotVarExp)]: Corrupted runtime on missed manifest constant propagation
A void returning statement 'return exp;' is rewritten to 'exp; return;'
but in that case an optimize() call was missing, which was just a little above.
https://github.com/dlang/dmd/pull/13290
Comment #5 by dlang-bot — 2021-12-14T10:34:09Z
dlang/dmd pull request #13421 "merge stable" was merged into master:
- 5963faf30fadd73f3ad56b5655a083962e85a80d by Boris Carvajal:
Fix Issue 16579 - ReturnStatement[CallExp(DotVarExp)]: Corrupted runtime on missed manifest constant propagation
A void returning statement 'return exp;' is rewritten to 'exp; return;'
but in that case an optimize() call was missing, which was just a little above.
https://github.com/dlang/dmd/pull/13421