← Back to index
|
Original Bugzilla link
Bug 3688 – Can't have declaration with assignment to const/immutable inside if condition
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-01-07T14:47:00Z
Last change time
2011-05-31T19:14:59Z
Keywords
rejects-valid
Assigned to
nobody
Creator
tomeksowi
Comments
Comment #0
by tomeksowi — 2010-01-07T14:47:07Z
Should pass: if (const int a = 4) // Error: variable test.main.a cannot modify const assert (a==4);
Comment #1
by k.hara.pg — 2011-04-18T20:20:18Z
More comprehensive code. ---- struct S { int v; this(int n) { v = n; } const bool opCast(T:bool)() { return true; } } void main() { if (int a = 1) assert(a == 1); else assert(0); if (const int a = 2) assert(a == 2); else assert(0); if (immutable int a = 3) assert(a == 3); else assert(0); if (auto s = S(10)) assert(s.v == 10); else assert(0); if (auto s = const(S)(20)) assert(s.v == 20); else assert(0); if (auto s = immutable(S)(30)) assert(s.v == 30); else assert(0); } ----
Comment #2
by bugzilla — 2011-05-29T10:33:45Z
See:
https://github.com/D-Programming-Language/dmd/pull/35
which needs more work.
Comment #3
by bugzilla — 2011-05-31T19:14:59Z
https://github.com/D-Programming-Language/dmd/commit/e921b529a022fda0e01153464fc0f91e83647ba5
https://github.com/D-Programming-Language/dmd/commit/e122d4ade8ebf7d117825494598e047369ebbe48
https://github.com/D-Programming-Language/dmd/commit/f84fb58a03456996cc579253901acce5b72a5138