Bug 15396 – static immutable not recognized as constant within switch statement

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-02T18:20:00Z
Last change time
2016-01-03T14:02:37Z
Keywords
rejects-valid
Assigned to
nobody
Creator
mathias.lang

Comments

Comment #0 by mathias.lang — 2015-12-02T18:20:04Z
Test case: ````` static immutable Foo = "Foobar"; void main (string[] args) { foreach (arg; args) { switch (arg) { case Foo: assert(0); default: continue; } } } ````` This should be accepted by the compiler but it currently produces: test.d(9): Error: case must be a string or an integral constant, not Foo Tested with 2.066 and 2.069.
Comment #1 by github-bugzilla — 2015-12-03T06:17:52Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/260a01fe80a3383a28e20ca18d03fc34615e4db4 Fix issue 15396 - static immutable doesn't work in case statement We should pass `WANTexpand` to `optimize` in addition to `WANTvalue` in order to get the value out of `static immutable` (and `static const`) variable. https://github.com/D-Programming-Language/dmd/commit/fb91273fab2148eb8d80f80de31a2e7df30bb544 Merge pull request #5295 from mathias-lang-sociomantic/fix-15396 Fix issue 15396 - static immutable doesn't work in case statement
Comment #2 by github-bugzilla — 2016-01-03T14:02:37Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/260a01fe80a3383a28e20ca18d03fc34615e4db4 Fix issue 15396 - static immutable doesn't work in case statement https://github.com/D-Programming-Language/dmd/commit/fb91273fab2148eb8d80f80de31a2e7df30bb544 Merge pull request #5295 from mathias-lang-sociomantic/fix-15396