Bug 8690 – Can't access a global enum size_t from a pure function

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-18T20:04:00Z
Last change time
2013-01-16T07:34:55Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-09-18T20:04:01Z
int[1] foo; enum fooLength = 1; void main() pure { auto n1 = fooLength; // OK auto n2 = foo.length; // error } DMD 2.061alpha shows: test.d(5): Error: pure function 'D main' cannot access mutable static data 'foo' But foo.length is a compile-time constant.
Comment #1 by yebblies — 2013-01-16T07:28:05Z
While this probably should work, it's tricky to implement because semantic has to work out what foo is to find length, and that triggers the purity check _long_ before it works out length is constant. Workaround: use typeof(foo).length
Comment #2 by yebblies — 2013-01-16T07:34:55Z
*** This issue has been marked as a duplicate of issue 6654 ***