Thread overview
[Issue 11853] New: Tuples fail "isAssignable"
Dec 31, 2013
Walter Bright
December 31, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11853

           Summary: Tuples fail "isAssignable"
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: monarchdodra@gmail.com


--- Comment #0 from monarchdodra@gmail.com 2013-12-31 04:00:39 PST ---
Works in 2.064.2. Fails in master:

//----
import std.traits, std.typecons;

void main()
{
    alias T = Tuple!int;
    static assert(isAssignable!T);
}
//----
main.d(6): Error: static assert  (isAssignable!(Tuple!int)) is false
//----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11853



--- Comment #1 from monarchdodra@gmail.com 2013-12-31 08:17:41 PST ---
According to "dissect", the faulty commit is:
Fix swap for non-assignable:
https://github.com/D-Programming-Language/phobos/commit/97e1fb80d404899cc14d03483f61986791747e38#diff-ff74a46362b5953e8c88120e2490f839

Which added this static test in "swap":
static if (!isAssignable!T || hasElaborateAssign!T)

The bummer is that tuple's opAssign looks like:

        void opAssign(R)(auto ref R rhs)
        if (areCompatibleTuples!(typeof(this), R, "="))
        {
            import std.algorithm : swap;
            swap!(Tuple!Types)(this, rhs);

I'm not quite sure *how* the compiler resolves that:
1. To instantiate opAssign, we need swap...
2. For swap we need to know if assignable...
3. To know if assignable, we need to instantiate opAssign...

In particular, it gives "funny" scenarios such as:

//----
alias T = Tuple!int;

void main()
{
    T t;
    static assert(isAssignable!T); //FAILS
}
//----
alias T = Tuple!int;

void main()
{
    T t;
    t = T.init;
    static assert(isAssignable!T); //PASSES
}
//----

We can workaround the problem by checking "hasElaborateAssign" first, as that check does not actually look into the implementation. Still, there is some bad smell here.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11853



--- Comment #2 from github-bugzilla@puremagic.com 2013-12-31 10:22:14 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/5d583483e3a997562d036dac872ae8548e73483f fix Issue 11853 - Tuples fail "isAssignable"

https://github.com/D-Programming-Language/phobos/commit/327085b8fed061853b0a9c8bdc42df9e495d0315 Merge pull request #1826 from monarchdodra/11853

fix Issue 11853 - Tuples fail "isAssignable"

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11853


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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