Bug 2442 – opApply does not allow inferring parameter types when overloaded on const

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-11-06T09:33:00Z
Last change time
2015-06-09T01:20:17Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2008-11-06T09:33:42Z
If I have the following code: struct S { int[] arr; int opApply(int delegate(ref int v) dg) { int result = 0; foreach(ref x; arr) { if(result = dg(x)) break; } return result; } int opApply(int delegate(ref const(int) v) dg) const { int result = 0; foreach(ref x; arr) { if(result = dg(x)) break; } return result; } } This is a properly const-decorated struct. I should be able to call foreach(x; s) Whether s is const or not. However, the compiler currently gives me an error: void main() { S s; foreach(x; s) { x = 5; } } testit.d(32): Error: cannot uniquely infer foreach argument types
Comment #1 by schveiguy — 2008-11-06T09:34:51Z
Note that this is a blocker for Tango
Comment #2 by yebblies — 2011-06-13T12:08:24Z
Comment #3 by k.hara.pg — 2011-12-26T02:04:30Z
Comment #4 by bugzilla — 2011-12-26T16:40:26Z