digitalmars.D.bugs - [Issue 7736] New: opApply for immutable structs too
- d-bugmail puremagic.com (50/50) Mar 19 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7736
- d-bugmail puremagic.com (13/13) Mar 19 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7736
- d-bugmail puremagic.com (34/71) Mar 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7736
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 puremagic.com ReportedBy: bearophile_hugs eml.cc --- Comment #0 from bearophile_hugs 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: -------
Mar 19 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7736 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug yahoo.com.au Summary|opApply for immutable |Regression(2.059 beta): |structs too |opApply for immutable | |structs too --- Comment #1 from Don <clugdbug yahoo.com.au> 2012-03-19 22:42:26 PDT --- Worked in 2.058. This bug hasn't appeared in an official release. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 19 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7736 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2012-03-29 21:28:19 PDT --- This issue is introduced by fixing bug 7038. (In reply to comment #0)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)) {} }In 2.058 and before, This code was equivalent to the following: struct __Foo { immutable: // a type qualifier for whole the struct affects to all its members [snip] // same as original code } alias immutable(__Foo) Foo; // Foo is always immutable(__Foo) void main() { foreach (i; Foo(10)) {} // Foo(10) is an immutable object, so immutable opApply works as well. }DMD 2.059 gives: test.d(13): Error: cannot uniquely infer foreach argument typesAfter fixing bug 7038, 'Foo' is always mutable type. struct Foo { immutable: // same as 2.058 and earlier [snip] // same as original code } void main() { foreach (i; Foo(10)) {} // Foo(10) is a mutable object, so immutable opApply *doesn't work* as well. }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)) {} }Because const opApply works with mutable object. Therefore, this is a "resolved-invalid bug" in 2.059, not a regression. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 29 2012