[Issue 8709] toLower on alias this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 9 01:52:30 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=8709


Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|NEW                         |RESOLVED
                 CC|                            |verylonglogin.reg at gmail.com
          Component|DMD                         |Phobos
         Resolution|                            |WORKSFORME


--- Comment #5 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-11-09 12:52:12 MSK ---
(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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list