Bug 8709 – toLower on alias this

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-23T02:58:00Z
Last change time
2013-11-09T01:52:12Z
Keywords
rejects-valid
Assigned to
nobody
Creator
luka8088

Comments

Comment #0 by luka8088 — 2012-09-23T02:58:17Z
// it used to work in DMD2 0.57 module program; import std.stdio; import std.string; struct myStruct { alias value this; string value; } void main () { myStruct s1; s1.value = "Test"; writeln(s1); // outputs "Test" writeln(s1.toLower()); // phobos/std/string.d(871): Error: e2ir: cannot cast result of type char[] to type myStruct }
Comment #1 by issues.dlang — 2012-09-23T03:40:50Z
Reduced test case: struct S { alias value this; string value; } void main () { auto s = S("hello"); char[] arr = "world".dup; s = cast(S)"other"; s = cast(S)arr; } The cast from string to S works, but the cast from char[] to S does not, in spite of the fact that their only difference is constness. However, the fact that this came up with std.string.toLower just highlights how error-prone it is to use alias this with templated functions. It's insanely easy to have template constraints which pass just fine due to the presense of alias this but then fail to actually compile or which behave bizarrely due to when conversions do and don't happen. I don't know what the solution to that is though.
Comment #2 by github-bugzilla — 2012-10-04T11:55:10Z
Comment #3 by monarchdodra — 2012-10-04T12:51:09Z
(In reply to comment #2) > Commits pushed to master at https://github.com/D-Programming-Language/phobos > > https://github.com/D-Programming-Language/phobos/commit/d028ef99edd51684f99749d9a2172f95b992c955 > fix issue 8709, from documentation > > https://github.com/D-Programming-Language/phobos/commit/bbdbfc7bc0aad1d744b709188e71add3aa27f94a > Merge pull request #823 from monarchdodra/toAA > > fix issue 8709, from documentation Typo in fix number, The above has NOTHING to do with this. Sorry.
Comment #4 by github-bugzilla — 2012-10-04T13:15:44Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/08722ad38a6f38eeade54a55102153b9765f13c1 Revert "fix issue 8709, from documentation" This reverts commit d028ef99edd51684f99749d9a2172f95b992c955. This is causing the build to fail and needs to be fixed before being merged in again.
Comment #5 by verylonglogin.reg — 2013-11-09T01:52:12Z
(In reply to comment #1) > Reduced test case: It is not a reduced testcase. See below. > struct S > { > alias value this; > string value; > } > > void main () > { > auto s = S("hello"); > char[] arr = "world".dup; > s = cast(S)"other"; > s = cast(S)arr; > } > > The cast from string to S works, but the cast from char[] to S does not, in > spite of the fact that their only difference is constness. `alias this` has nothing to do with casting to type and it is just rewritten to `S(...)` and as `char[]` isn't implicitly convertible to `string` it fails. So the behavior is correct. > However, the fact that this came up with std.string.toLower just highlights how > error-prone it is to use alias this with templated functions. It's insanely > easy to have template constraints which pass just fine due to the presense of > alias this but then fail to actually compile or which behave bizarrely due to > when conversions do and don't happen. I don't know what the solution to that is > though. Agree. So the issue is Phobos one, not dmd one. And `toLower` works now.