diff --git a/std/traits.d b/std/traits.d index 11e160ce75a..7d45099982a 100644 --- a/std/traits.d +++ b/std/traits.d @@ -5180,10 +5180,10 @@ enum isAssignable(Lhs, Rhs = Lhs) = isRvalueAssignable!(Lhs, Rhs) && isLvalueAss } // ditto -private enum isRvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lhs = rvalueOf!Rhs); +private enum isRvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, { lvalueOf!Lhs = rvalueOf!Rhs; }); // ditto -private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lhs = lvalueOf!Rhs); +private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, { lvalueOf!Lhs = lvalueOf!Rhs; }); @safe unittest { @@ -5219,11 +5219,26 @@ private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lh static assert( isAssignable!(S4, immutable int)); struct S5 { @disable this(); @disable this(this); } - struct S6 { void opAssign(in ref S5); } - static assert(!isAssignable!(S6, S5)); - static assert(!isRvalueAssignable!(S6, S5)); - static assert( isLvalueAssignable!(S6, S5)); - static assert( isLvalueAssignable!(S6, immutable S5)); + + // `-preview=in` is enabled + static if (!is(typeof(mixin(q{(in ref int a) => a})))) + { + struct S6 { void opAssign(in S5); } + + static assert(isRvalueAssignable!(S6, S5)); + static assert(isLvalueAssignable!(S6, S5)); + static assert(isAssignable!(S6, S5)); + static assert(isAssignable!(S6, immutable S5)); + } + else + { + mixin(q{ struct S6 { void opAssign(in ref S5); } }); + + static assert(!isRvalueAssignable!(S6, S5)); + static assert( isLvalueAssignable!(S6, S5)); + static assert(!isAssignable!(S6, S5)); + static assert( isLvalueAssignable!(S6, immutable S5)); + } }