Bug 6782 – inout-correct range is not iterable using foreach with type deduction inside non-inout function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-10-07T13:07:00Z
Last change time
2011-10-08T16:26:38Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2011-10-07T13:07:02Z
This should compile: struct range { int *ptr; @property inout(int)* front() inout { return ptr; } @property bool empty() const { return ptr is null; } void popFront() { ptr = null; } } void main() { int x = 5; auto r = range(&x); foreach(p; r) // line 24 { } } bug.d(24): Error: variable bug.main.p inout variables can only be declared inside inout functions bug.d(24): Error: cannot implicitly convert expression (__r1.front()) of type int* to inout(int)* The range foreach rewrite somehow gets inout into the resulting type of r.front, where it should really be the resulting wild type (in this case int*) Changing the foreach loop to: foreach(int *p; r) { } compiles.
Comment #1 by k.hara.pg — 2011-10-07T16:07:18Z
Comment #2 by bugzilla — 2011-10-08T16:26:38Z