[Issue 7736] New: opApply for immutable structs too
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 19 16:29:30 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7736
Summary: opApply for immutable structs too
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: rejects-valid
Severity: regression
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-03-19 16:29:47 PDT ---
This code used to work not too much time ago (maybe 2.056?):
immutable struct Foo {
char stop;
int opApply(int delegate(ref int) dg) {
int result;
for (int i = 0; i < stop; i++) {
result = dg(i);
if (result) break;
}
return result;
}
}
void main() {
foreach (i; Foo(10)) {}
}
DMD 2.059 gives:
test.d(13): Error: cannot uniquely infer foreach argument types
The code compiles and works if you remove the "immutable" and replace it with
const:
const struct Foo {
char stop;
int opApply(int delegate(ref int) dg) {
int result;
for (int i = 0; i < stop; i++) {
result = dg(i);
if (result) break;
}
return result;
}
}
void main() {
foreach (i; Foo(10)) {}
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list