Thread overview
[Issue 8264] New: [std.conv.to] constructing conversion doesn't work with alias this
Jun 19, 2012
Kenji Hara
Jun 19, 2012
Jonathan M Davis
Jun 19, 2012
Kenji Hara
Jun 19, 2012
Kenji Hara
Jun 21, 2012
Jonathan M Davis
June 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264

           Summary: [std.conv.to] constructing conversion doesn't work
                    with alias this
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: k.hara.pg@gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-18 22:28:24 PDT ---
from http://forum.dlang.org/thread/mailman.1606.1340038410.24740.digitalmars-d-learn@puremagic.com#post-cetlbrtfhbtunchppikq:40forum.dlang.org

----
This kind conversions should be possible with std.conv.to.

import std.conv;
struct Wrap
{
    string wrap;
    alias wrap this;
}
void main()
{
    Wrap[] y = to!(Wrap[])(["foo", "bar"]);  // shold work
}

If you can construct Wrap object with the syntax Wrap("foo"),
std.conv.to runs 'conversion by construction'.
And if S is convertible to T, std.conv.to!(T[])(S[] source) runs
'element-wise array conversion'.
As a result, string[] to Wrap[] will be converted.

...but, this does not work in 2.060head, it is a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-06-18 22:45:19 PDT ---
Is it really bug? What if you have

struct Wrap
{
    string wrap;
    int i;
    double d;
    string s;

    alias wrap this;
}

Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init, string.init)? Or should it not work? Maybe it should work, but it seems a bit funny to me to create a Wrap from just a string considering that the alias doesn't define how to initialize the rest of the object.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-18 23:16:52 PDT ---
(In reply to comment #1)
> Is it really bug?

Yes. The problem is that declaring alias this is incorrectly matches more than two templates. If you remove 'alias wrap this' from Wrap type, the conversion will succeed.

> What if you have
> 
> struct Wrap
> {
>     string wrap;
>     int i;
>     double d;
>     string s;
> 
>     alias wrap this;
> }
> 
> Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init, string.init)? Or should it not work? Maybe it should work, but it seems a bit funny to me to create a Wrap from just a string considering that the alias doesn't define how to initialize the rest of the object.

I also it seems a bit funny, but it should work.
std.conv.to supports constructing conversion based on _syntactic possibilities_
- like range interface: r.empty, r.front, and r.popFront().
I think such limitation provides no benefit.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-18 23:39:56 PDT ---
https://github.com/D-Programming-Language/phobos/pull/640

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264



--- Comment #4 from github-bugzilla@puremagic.com 2012-06-20 20:59:39 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/18564f4fa20bd7d3c66e0d37494d4305edb048fd
fix Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias
this

https://github.com/D-Programming-Language/phobos/commit/32d9b329057a01b5775c4cfdebc869f86ca0c691 Merge pull request #640 from 9rnsr/fix8264

Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias this

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264



--- Comment #5 from github-bugzilla@puremagic.com 2012-06-20 21:02:02 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/2a3b0b0ffe12a25e5f0a1e9e5b6535a0a531cb33 Updated changelog for fix for issue# 8264.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Jonathan M Davis <jmdavisProg@gmx.com> 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: -------