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
//----
Comment #1 by monarchdodra — 2013-12-31T08:17:41Z
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.
Comment #2 by github-bugzilla — 2013-12-31T10:22:14Z