Fix issue 15320

This commit is contained in:
Dragos Carp 2015-11-13 03:45:29 +01:00
parent f5ce17346d
commit eb293b5063
11 changed files with 1038 additions and 1043 deletions

View file

@ -765,14 +765,14 @@ unittest
// Issue #10130 - map of iota with const step. // Issue #10130 - map of iota with const step.
const step = 2; const step = 2;
static assert(__traits(compiles, map!(i => i)(iota(0, 10, step)))); map!(i => i)(iota(0, 10, step));
// Need these to all by const to repro the float case, due to the // Need these to all by const to repro the float case, due to the
// CommonType template used in the float specialization of iota. // CommonType template used in the float specialization of iota.
const floatBegin = 0.0; const floatBegin = 0.0;
const floatEnd = 1.0; const floatEnd = 1.0;
const floatStep = 0.02; const floatStep = 0.02;
static assert(__traits(compiles, map!(i => i)(iota(floatBegin, floatEnd, floatStep)))); map!(i => i)(iota(floatBegin, floatEnd, floatStep));
} }
@safe unittest @safe unittest

View file

@ -573,12 +573,12 @@ void fill(Range, Value)(Range range, Value value)
{ {
int[] a = [1, 2, 3]; int[] a = [1, 2, 3];
immutable(int) b = 0; immutable(int) b = 0;
static assert(__traits(compiles, a.fill(b))); a.fill(b);
} }
{ {
double[] a = [1, 2, 3]; double[] a = [1, 2, 3];
immutable(int) b = 0; immutable(int) b = 0;
static assert(__traits(compiles, a.fill(b))); a.fill(b);
} }
} }
@ -982,8 +982,7 @@ unittest
class S5; class S5;
S5 s51; S5 s51;
static assert(__traits(compiles, move(s51, s51)), move(s51, s51);
"issue 13990, cannot move opaque class reference");
} }
/// Ditto /// Ditto
@ -1093,8 +1092,7 @@ unittest
class S5; class S5;
S5 s51; S5 s51;
static assert(__traits(compiles, s51 = move(s51)), s51 = move(s51);
"issue 13990, cannot move opaque class reference");
} }
unittest unittest
@ -1103,8 +1101,8 @@ unittest
S a, b; S a, b;
static assert(!__traits(compiles, () @safe { move(a, b); })); static assert(!__traits(compiles, () @safe { move(a, b); }));
static assert(!__traits(compiles, () @safe { move(a); })); static assert(!__traits(compiles, () @safe { move(a); }));
static assert(__traits(compiles, () @trusted { move(a, b); })); () @trusted { move(a, b); }();
static assert(__traits(compiles, () @trusted { move(a); })); () @trusted { move(a); }();
} }
unittest//Issue 6217 unittest//Issue 6217
@ -1166,8 +1164,8 @@ unittest// Issue 8057
} }
} }
Array!int.Payload x = void; Array!int.Payload x = void;
static assert(__traits(compiles, move(x) )); move(x);
static assert(__traits(compiles, move(x, x) )); move(x, x);
} }
/** /**

View file

@ -377,7 +377,7 @@ unittest
import std.typecons; import std.typecons;
static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray())); static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray()));
static assert(!__traits(compiles, [ tuple("foo") ].assocArray())); static assert(!__traits(compiles, [ tuple("foo") ].assocArray()));
static assert( __traits(compiles, [ tuple("foo", "bar") ].assocArray())); [ tuple("foo", "bar") ].assocArray();
} }
// Issue 13909 // Issue 13909
@ -386,7 +386,7 @@ unittest
import std.typecons; import std.typecons;
auto a = [tuple!(const string, string)("foo", "bar")]; auto a = [tuple!(const string, string)("foo", "bar")];
auto b = [tuple!(string, const string)("foo", "bar")]; auto b = [tuple!(string, const string)("foo", "bar")];
static assert( __traits(compiles, assocArray(a))); assocArray(a);
static assert(!__traits(compiles, assocArray(b))); static assert(!__traits(compiles, assocArray(b)));
} }

File diff suppressed because it is too large Load diff

View file

@ -982,10 +982,10 @@ template Alias(a...)
unittest unittest
{ {
enum abc = 1; enum abc = 1;
static assert(__traits(compiles, { alias a = Alias!(123); })); alias a = Alias!(123);
static assert(__traits(compiles, { alias a = Alias!(abc); })); alias b = Alias!(abc);
static assert(__traits(compiles, { alias a = Alias!(int); })); alias c = Alias!(int);
static assert(__traits(compiles, { alias a = Alias!(1,abc,int); })); alias d = Alias!(1, abc, int);
} }

View file

@ -1555,9 +1555,8 @@ auto chainPath(Ranges...)(auto ref Ranges ranges)
unittest unittest
{ {
chainPath(TestAliasedString(null), TestAliasedString(null), TestAliasedString(null)); chainPath(TestAliasedString(null), TestAliasedString(null), TestAliasedString(null));
static assert(__traits(compiles, chainPath(TestAliasedString(null), TestAliasedString(null), TestAliasedString(null)))); chainPath(TestAliasedString(null), TestAliasedString(null), "");
static assert(__traits(compiles, chainPath(TestAliasedString(null), TestAliasedString(null), ""))); chainPath(TestAliasedString(null), "", TestAliasedString(null));
static assert(__traits(compiles, chainPath(TestAliasedString(null), "", TestAliasedString(null))));
static struct S { string s; } static struct S { string s; }
static assert(!__traits(compiles, chainPath(TestAliasedString(null), S(""), TestAliasedString(null)))); static assert(!__traits(compiles, chainPath(TestAliasedString(null), S(""), TestAliasedString(null))));
} }
@ -2903,11 +2902,11 @@ unittest
assert (asRelativePath(TestAliasedString("foo"), TestAliasedString("/bar")).array == "foo"); assert (asRelativePath(TestAliasedString("foo"), TestAliasedString("/bar")).array == "foo");
else version (Windows) else version (Windows)
assert (asRelativePath(TestAliasedString("foo"), TestAliasedString(`c:\bar`)).array == "foo"); assert (asRelativePath(TestAliasedString("foo"), TestAliasedString(`c:\bar`)).array == "foo");
static assert(__traits(compiles, asRelativePath(TestAliasedString(null), ""))); assert(asRelativePath(TestAliasedString("foo"), "bar").array == "foo");
static assert(__traits(compiles, asRelativePath("", TestAliasedString(null)))); assert(asRelativePath("foo", TestAliasedString("bar")).array == "foo");
static assert(__traits(compiles, asRelativePath(TestAliasedString(null), TestAliasedString(null)))); assert(asRelativePath(TestAliasedString("foo"), TestAliasedString("bar")).array == "foo");
import std.utf : byDchar; import std.utf : byDchar;
static assert(__traits(compiles, asRelativePath(""d.byDchar, TestAliasedString(null)))); assert(asRelativePath("foo"d.byDchar, TestAliasedString("bar")).array == "foo");
} }
unittest unittest

View file

@ -3871,8 +3871,8 @@ unittest
} }
// BUG 8900 // BUG 8900
static assert(__traits(compiles, zip([1, 2], repeat('a')))); assert(zip([1, 2], repeat('a')).array == [tuple(1, 'a'), tuple(2, 'a')]);
static assert(__traits(compiles, zip(repeat('a'), [1, 2]))); assert(zip(repeat('a'), [1, 2]).array == [tuple('a', 1), tuple('a', 2)]);
// Doesn't work yet. Issues w/ emplace. // Doesn't work yet. Issues w/ emplace.
// static assert(is(Zip!(immutable int[], immutable float[]))); // static assert(is(Zip!(immutable int[], immutable float[])));
@ -3944,7 +3944,7 @@ pure unittest
import std.exception : assertThrown; import std.exception : assertThrown;
static struct S { @disable this(); } static struct S { @disable this(); }
static assert(__traits(compiles, zip((S[5]).init[]))); zip((S[5]).init[]);
auto z = zip(StoppingPolicy.longest, cast(S[]) null, new int[1]); auto z = zip(StoppingPolicy.longest, cast(S[]) null, new int[1]);
assertThrown(zip(StoppingPolicy.longest, cast(S[]) null, new int[1]).front); assertThrown(zip(StoppingPolicy.longest, cast(S[]) null, new int[1]).front);
} }
@ -4212,9 +4212,10 @@ unittest
static assert(!__traits(compiles, { static assert(!__traits(compiles, {
foreach (ref a, ref b; lockstep(r1, r2)) { a++; } foreach (ref a, ref b; lockstep(r1, r2)) { a++; }
})); }));
static assert(__traits(compiles, { foreach (a, ref b; lockstep(r1, r2))
foreach (a, ref b; lockstep(r1, r2)) { a++; } {
})); a++;
}
} }
/** /**

View file

@ -444,14 +444,14 @@ unittest
{ {
int[] a = new int[10]; int[] a = new int[10];
static assert(!__traits(compiles, put(a, 1.0L))); static assert(!__traits(compiles, put(a, 1.0L)));
static assert( __traits(compiles, put(a, 1))); put(a, 1);
/* /*
* a[0] = 65; // OK * a[0] = 65; // OK
* a[0] = 'A'; // OK * a[0] = 'A'; // OK
* a[0] = "ABC"[0]; // OK * a[0] = "ABC"[0]; // OK
* put(a, "ABC"); // OK * put(a, "ABC"); // OK
*/ */
static assert( __traits(compiles, put(a, "ABC"))); put(a, "ABC");
} }
unittest unittest
@ -466,11 +466,11 @@ unittest
unittest unittest
{ {
int[][] a; int[][] a = new int[][10];
int[] b; int[] b = new int[10];
int c; int c;
static assert( __traits(compiles, put(b, c))); put(b, c);
static assert( __traits(compiles, put(a, b))); put(a, b);
static assert(!__traits(compiles, put(a, c))); static assert(!__traits(compiles, put(a, c)));
} }

View file

@ -979,7 +979,7 @@ unittest {
void bar(uint){} void bar(uint){}
static assert(arity!bar==1); static assert(arity!bar==1);
void variadicFoo(uint...){} void variadicFoo(uint...){}
static assert(__traits(compiles,arity!variadicFoo)==false); static assert(!__traits(compiles, arity!variadicFoo));
} }
/** /**

View file

@ -1161,8 +1161,7 @@ unittest
foreach (v1; AliasSeq!(mv, cv, iv, wv, wcv)) foreach (v1; AliasSeq!(mv, cv, iv, wv, wcv))
foreach (v2; AliasSeq!(mv, cv, iv, wv, wcv)) foreach (v2; AliasSeq!(mv, cv, iv, wv, wcv))
{ {
static assert(__traits(compiles, v1 < v2), cast(void) (v1 < v2);
typeof(v1).stringof ~ " < " ~ typeof(v2).stringof);
} }
} }
{ {
@ -2176,10 +2175,10 @@ unittest
{ {
auto sm = S1(1); auto sm = S1(1);
immutable si = immutable S1(1); immutable si = immutable S1(1);
static assert( __traits(compiles, { auto x1 = Nullable!S1(sm); })); auto x1 = Nullable!S1(sm);
static assert( __traits(compiles, { auto x2 = immutable Nullable!S1(sm); })); auto x2 = immutable Nullable!S1(sm);
static assert( __traits(compiles, { auto x3 = Nullable!S1(si); })); auto x3 = Nullable!S1(si);
static assert( __traits(compiles, { auto x4 = immutable Nullable!S1(si); })); auto x4 = immutable Nullable!S1(si);
} }
auto nm = 10; auto nm = 10;
@ -2188,19 +2187,19 @@ unittest
{ {
auto sm = S2(&nm); auto sm = S2(&nm);
immutable si = immutable S2(&ni); immutable si = immutable S2(&ni);
static assert( __traits(compiles, { auto x = Nullable!S2(sm); })); auto x1 = Nullable!S2(sm);
static assert(!__traits(compiles, { auto x = immutable Nullable!S2(sm); })); static assert(!__traits(compiles, { auto x2 = immutable Nullable!S2(sm); }));
static assert(!__traits(compiles, { auto x = Nullable!S2(si); })); static assert(!__traits(compiles, { auto x3 = Nullable!S2(si); }));
static assert( __traits(compiles, { auto x = immutable Nullable!S2(si); })); auto x4 = immutable Nullable!S2(si);
} }
{ {
auto sm = S3(&ni); auto sm = S3(&ni);
immutable si = immutable S3(&ni); immutable si = immutable S3(&ni);
static assert( __traits(compiles, { auto x = Nullable!S3(sm); })); auto x1 = Nullable!S3(sm);
static assert( __traits(compiles, { auto x = immutable Nullable!S3(sm); })); auto x2 = immutable Nullable!S3(sm);
static assert( __traits(compiles, { auto x = Nullable!S3(si); })); auto x3 = Nullable!S3(si);
static assert( __traits(compiles, { auto x = immutable Nullable!S3(si); })); auto x4 = immutable Nullable!S3(si);
} }
} }
unittest unittest
@ -6553,7 +6552,7 @@ public:
B = 1<<1, B = 1<<1,
C = 1<<2 C = 1<<2
} }
static assert(__traits(compiles, BitFlags!Enum)); BitFlags!Enum flags1;
// You need to specify the $(D unsafe) parameter for enum with custom values // You need to specify the $(D unsafe) parameter for enum with custom values
enum UnsafeEnum enum UnsafeEnum
@ -6563,8 +6562,8 @@ public:
C, C,
D = B|C D = B|C
} }
static assert(!__traits(compiles, BitFlags!UnsafeEnum)); static assert(!__traits(compiles, { BitFlags!UnsafeEnum flags2; }));
static assert(__traits(compiles, BitFlags!(UnsafeEnum, Yes.unsafe))); BitFlags!(UnsafeEnum, Yes.unsafe) flags3;
immutable BitFlags!Enum flags_empty; immutable BitFlags!Enum flags_empty;
// A default constructed BitFlags has no value set // A default constructed BitFlags has no value set

View file

@ -2983,7 +2983,7 @@ const(wchar)* toUTF16z(C)(const(C)[] str) @safe pure
//toUTFz is already thoroughly tested, so this will just verify that //toUTFz is already thoroughly tested, so this will just verify that
//toUTF16z compiles properly for the various string types. //toUTF16z compiles properly for the various string types.
foreach (S; AliasSeq!(string, wstring, dstring)) foreach (S; AliasSeq!(string, wstring, dstring))
static assert(__traits(compiles, toUTF16z(to!S("hello world")))); assert(toUTF16z(to!S("hello world")) !is null);
} }