Bug 8625 – foreach doesn't do implicit conversions with opApply

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-05T20:41:43Z
Last change time
2024-12-13T18:01:15Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Nils
Moved to GitHub: dmd#18466 →

Comments

Comment #0 by nilsbossung — 2012-09-05T20:41:43Z
This should compile: void main() { int[int] aa; foreach(long k, long v; aa) {} // fails on both k and v // test.d(3): Error: foreach: index must be type int, not long // test.d(3): Error: foreach: value must be type int, not long static struct OpApply { int opApply(int delegate(int)) {return 0;} } foreach(long x; OpApply()) {} // fails // test.d(10): Error: cannot uniquely infer foreach argument types // In contrast, it does work on plain arrays and ranges: int[] a; foreach(long x; a) {} // ok static struct Range { @property bool empty() {return false;} @property int front() {return 0;} void popFront() {} } foreach(long x; Range()) {} // ok }
Comment #1 by yebblies — 2013-11-23T20:31:10Z
This case still doesn't work void main() { static struct OpApply { int opApply(int delegate(int)) {return 0;} } foreach(long x; OpApply()) {} // fails // test.d(10): Error: cannot uniquely infer foreach argument types } The first was issue 9212
Comment #2 by robert.schadek — 2024-12-13T18:01:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18466 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB