digitalmars.D.bugs - [Issue 7878] New: A problem with purity and general templated algorithms
- d-bugmail puremagic.com (58/58) Apr 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (13/13) Apr 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (12/12) Apr 10 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (10/10) Apr 18 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (10/10) Apr 20 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (11/11) Jun 04 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
- d-bugmail puremagic.com (9/9) Jun 04 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7878
http://d.puremagic.com/issues/show_bug.cgi?id=7878 Summary: A problem with purity and general templated algorithms Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc --- Comment #0 from bearophile_hugs eml.cc 2012-04-09 10:54:17 PDT --- This is a spinoff of the closed Issue 7864 , see there for more info. This is not a bug report and it's not even a real enhancement request, it's just a note to not forget a small but what I think real problem in D+Phobos. At the moment I don't have suggestions to how improve the situation. Ideas are welcome. This is wrong D2 code: class C { string str; this(string str_) { this.str = str_; } override int opCmp(Object o) const { import std.string; auto rhs = cast(C)o; assert(rhs); return cmp(str, rhs.str); } } struct S { C c; int opCmp()(const auto ref S rhs) const pure { if (c < rhs.c) return -1; if (c > rhs.c) return 1; return 0; } } void main() { import std.algorithm; S[] stuff; sort(stuff); } DMD 2.059beta4 gives: ...\dmd2\src\phobos\std\algorithm.d(6802): Error: static assert "Invalid predicate passed to sort: a < b" test.d(29): instantiated from here: sort!("a < b",cast(SwapStrategy)0,S[]) The error message looks correct, but it's really too much general, it doesn't give enough information to the programmer, that is left to guess why the code doesn't work. This is quite bad. To fix this program the first opCmp too must be pure: override int opCmp(Object o) const pure { But in a little more complex program it risks being not easy to find such bugs. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 09 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|DMD |Phobos --- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-04-10 03:32:39 PDT --- It is std.functional.binaryFun and std.algorithm.sort problem, not compiler's. If the instantiation of predicate "a < b" that given to sort template function is failed, they hide actual errors and instead print their own error messages by static assert. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 Jonathan M Davis <jmdavisProg gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg gmx.com --- Comment #2 from Jonathan M Davis <jmdavisProg gmx.com> 2012-04-10 10:14:26 PDT --- That may be, but if overloaded operators are wrong (especially opEquals and opCmp), I would expect the compiler to give errors for those types before any instantiation of sort was even attempted, and clearly, that's not happening. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 10 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2012-04-18 18:00:47 PDT --- https://github.com/D-Programming-Language/phobos/pull/544 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 18 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich gmail.com --- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2012-04-20 23:47:09 PDT --- *** Issue 5505 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 --- Comment #5 from github-bugzilla puremagic.com 2012-06-04 01:39:01 PDT --- Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/e2c892fdbfd23f45c2f304edb761b18111857228 fix Issue 7878 - A problem with purity and general templated algorithms https://github.com/D-Programming-Language/phobos/commit/8e37bf3d01b59f620ed40bab8ee3943fab0289dc Merge pull request #544 from 9rnsr/fix7878 Issue 7878 - A problem with purity and general templated algorithms -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 04 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7878 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 04 2012