Skip to content

Commit

Permalink
Change deprecation error to warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 20, 2012
1 parent 57b770e commit 8519a3a
Show file tree
Hide file tree
Showing 11 changed files with 782 additions and 830 deletions.
14 changes: 7 additions & 7 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -10786,17 +10786,17 @@ Expression *AssignExp::semantic(Scope *sc)
e2 = new SliceExp(e2->loc, e2, NULL, NULL);
e2 = e2->semantic(sc);
}
else if (!global.params.useDeprecated && op == TOKassign &&
else if (global.params.warnings && !global.gag && op == TOKassign &&
e2->op != TOKarrayliteral && e2->op != TOKstring)
{ // Disallow sa = da (Converted to sa[] = da[])
// Disallow sa = e (Converted to sa[] = e)
const char* e1str = e1->toChars();
const char* e2str = e2->toChars();
if (e2->op == TOKslice || t2->implicitConvTo(t1->nextOf()))
error("implicit element-wise assignment %s = %s is deprecated, instead use (%s)[] = %s",
warning("explicit element-wise assignment (%s)[] = %s is better than %s = %s",
e1str, e2str, e1str, e2str);
else
error("implicit element-wise assignment %s = %s is deprecated, instead use (%s)[] = (%s)[]",
warning("explicit element-wise assignment (%s)[] = (%s)[] is better than %s = %s",
e1str, e2str, e1str, e2str);
return new ErrorExp();
}
Expand Down Expand Up @@ -10884,7 +10884,7 @@ Expression *AssignExp::semantic(Scope *sc)
{
checkPostblit(e2->loc, t2->nextOf());
}
if (!global.params.useDeprecated && op == TOKassign &&
if (global.params.warnings && !global.gag && op == TOKassign &&
e2->op != TOKslice && e2->op != TOKassign &&
e2->op != TOKarrayliteral && e2->op != TOKstring &&
!(e2->op == TOKadd || e2->op == TOKmin ||
Expand All @@ -10898,7 +10898,7 @@ Expression *AssignExp::semantic(Scope *sc)
{
const char* e1str = e1->toChars();
const char* e2str = e2->toChars();
error("implicit element-wise assignment %s = %s is deprecated, instead use %s = (%s)[]",
warning("explicit element-wise assignment %s = (%s)[] is better than %s = %s",
e1str, e2str, e1str, e2str);
return new ErrorExp();
}
Expand All @@ -10909,15 +10909,15 @@ Expression *AssignExp::semantic(Scope *sc)
}
else
{
if (!global.params.useDeprecated && op == TOKassign &&
if (global.params.warnings && !global.gag && op == TOKassign &&
t1->ty == Tarray && t2->ty == Tsarray &&
e2->op != TOKslice && //e2->op != TOKarrayliteral &&
t2->implicitConvTo(t1))
{ // Disallow ar[] = sa (Converted to ar[] = sa[])
// Disallow da = sa (Converted to da = sa[])
const char* e1str = e1->toChars();
const char* e2str = e2->toChars();
error("implicit %s assignment %s = %s is deprecated, instead use %s = (%s)[]",
warning("explicit %s assignment %s = (%s)[] is better than %s = %s",
e1->op == TOKslice ? "element-wise" : "slice",
e1str, e2str, e1str, e2str);
return new ErrorExp();
Expand Down
67 changes: 0 additions & 67 deletions test/compilable/deprecate2.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,3 @@ class B3836 : A3836
{
void fun() {}
}

/**************************************************
Moved by fixing issue 7444
From derivedarray.d
**************************************************/

void statictodynamicarrays()
{
static class C {}
static class D : C {}

C[] a;
D[] b;
const(C)[] c;
const(D)[] d;
immutable(C)[] e;
immutable(D)[] f;

C[1] sa;
D[1] sb;
const(C)[1] sc = void;
const(D)[1] sd = void;
immutable(C)[1] se = void;
immutable(D)[1] sf = void;

static assert( __traits(compiles, a = sa));
static assert(!__traits(compiles, a = sb));
static assert(!__traits(compiles, a = sc));
static assert(!__traits(compiles, a = sd));
static assert(!__traits(compiles, a = se));
static assert(!__traits(compiles, a = sf));

static assert(!__traits(compiles, b = sa));
static assert( __traits(compiles, b = sb));
static assert(!__traits(compiles, b = sc));
static assert(!__traits(compiles, b = sd));
static assert(!__traits(compiles, b = se));
static assert(!__traits(compiles, b = sf));

static assert( __traits(compiles, c = sa));
static assert( __traits(compiles, c = sb));
static assert( __traits(compiles, c = sc));
static assert( __traits(compiles, c = sd));
static assert( __traits(compiles, c = se));
static assert( __traits(compiles, c = sf));

static assert(!__traits(compiles, d = sa));
static assert( __traits(compiles, d = sb));
static assert(!__traits(compiles, d = sc));
static assert( __traits(compiles, d = sd));
static assert(!__traits(compiles, d = se));
static assert( __traits(compiles, d = sf));

static assert(!__traits(compiles, e = sa));
static assert(!__traits(compiles, e = sb));
static assert(!__traits(compiles, e = sc));
static assert(!__traits(compiles, e = sd));
static assert( __traits(compiles, e = se));
static assert( __traits(compiles, e = sf));

static assert(!__traits(compiles, f = sa));
static assert(!__traits(compiles, f = sb));
static assert(!__traits(compiles, f = sc));
static assert(!__traits(compiles, f = sd));
static assert(!__traits(compiles, f = se));
static assert( __traits(compiles, f = sf));
}
59 changes: 59 additions & 0 deletions test/compilable/derivedarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,65 @@ void dynamicarrays()
}


void statictodynamicarrays()
{
C[] a;
D[] b;
const(C)[] c;
const(D)[] d;
immutable(C)[] e;
immutable(D)[] f;

C[1] sa;
D[1] sb;
const(C)[1] sc = void;
const(D)[1] sd = void;
immutable(C)[1] se = void;
immutable(D)[1] sf = void;

static assert( __traits(compiles, a = sa));
static assert(!__traits(compiles, a = sb));
static assert(!__traits(compiles, a = sc));
static assert(!__traits(compiles, a = sd));
static assert(!__traits(compiles, a = se));
static assert(!__traits(compiles, a = sf));

static assert(!__traits(compiles, b = sa));
static assert( __traits(compiles, b = sb));
static assert(!__traits(compiles, b = sc));
static assert(!__traits(compiles, b = sd));
static assert(!__traits(compiles, b = se));
static assert(!__traits(compiles, b = sf));

static assert( __traits(compiles, c = sa));
static assert( __traits(compiles, c = sb));
static assert( __traits(compiles, c = sc));
static assert( __traits(compiles, c = sd));
static assert( __traits(compiles, c = se));
static assert( __traits(compiles, c = sf));

static assert(!__traits(compiles, d = sa));
static assert( __traits(compiles, d = sb));
static assert(!__traits(compiles, d = sc));
static assert( __traits(compiles, d = sd));
static assert(!__traits(compiles, d = se));
static assert( __traits(compiles, d = sf));

static assert(!__traits(compiles, e = sa));
static assert(!__traits(compiles, e = sb));
static assert(!__traits(compiles, e = sc));
static assert(!__traits(compiles, e = sd));
static assert( __traits(compiles, e = se));
static assert( __traits(compiles, e = sf));

static assert(!__traits(compiles, f = sa));
static assert(!__traits(compiles, f = sb));
static assert(!__traits(compiles, f = sc));
static assert(!__traits(compiles, f = sd));
static assert(!__traits(compiles, f = se));
static assert( __traits(compiles, f = sf));
}

void staticarrays()
{
C[1] sa;
Expand Down
28 changes: 14 additions & 14 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -638,14 +638,14 @@ immutable int[1][1] bug5147imm = bug5147();
// Index referencing
int[2][2] indexref() {
int[2][2] a = 2;
a[0][]=7;
a[0]=7;

int[][] b = [null, null];
b[0..$] = a[0][0..2];
assert(b[0][0]==7);
assert(b[0][1]==7);
int [] w;
w = a[0][];
w = a[0];
assert(w[0]==7);
w[0..$] = 5;
assert(a[0]!=[7,7]);
Expand All @@ -655,15 +655,15 @@ int[2][2] indexref() {
}
int[2][2] indexref2() {
int[2][2] a = 2;
a[0][]=7;
a[0]=7;

int[][2] b = null;
b[0..$] = a[0];
assert(b[0][0]==7);
assert(b[0][1]==7);
assert(b == [[7,7], [7,7]]);
int [] w;
w = a[0][];
w = a[0];
assert(w[0]==7);
w[0..$] = 5;
assert(a[0]!=[7,7]);
Expand All @@ -673,14 +673,14 @@ int[2][2] indexref2() {
}
int[2][2] indexref3() {
int[2][2] a = 2;
a[0][]=7;
a[0]=7;

int[][2] b = [null, null];
b[0..$] = a[0];
assert(b[0][0]==7);
assert(b[0][1]==7);
int [] w;
w = a[0][];
w = a[0];
assert(w[0]==7);
w[0..$] = 5;
assert(a[0]!=[7,7]);
Expand All @@ -690,14 +690,14 @@ int[2][2] indexref3() {
}
int[2][2] indexref4() {
int[2][2] a = 2;
a[0][]=7;
a[0]=7;

int[][2] b =[[1,2,3],[1,2,3]]; // wrong code
b[0] = a[0][];
b[0] = a[0];
assert(b[0][0]==7);
assert(b[0][1]==7);
int [] w;
w = a[0][]; //[0..$];
w = a[0]; //[0..$];
assert(w[0]==7);
w[0..$] = 5;
assert(a[0]!=[7,7]);
Expand Down Expand Up @@ -1126,11 +1126,11 @@ int quop()
int [] heap = new int[5];
heap[] = 738;
Zadok pong;
pong.z[] = 3;
pong.z = 3;
int [] w = pong.z;
assert(w[0]==3);
Zadok phong;
phong.z[] = 61;
phong.z = 61;
pong = phong;
assert(w[0]==61);
Vug b = Vug(Zadok(17, "abcd"));
Expand All @@ -1140,7 +1140,7 @@ int quop()
char [] y = b.p.s;
assert(y[2]=='c');
phong.s = ['z','x','f', 'g'];
w = b.p.z[];
w = b.p.z;
assert(y[2]=='c');
assert(w[0]==17);
b.p = phong;
Expand Down Expand Up @@ -1576,9 +1576,9 @@ static assert(bug6052());
bool bug6052b() {
int[][1] arr;
int[1] z = [7];
arr[0] = z[];
arr[0] = z;
assert(arr[0][0] == 7);
arr[0] = z[];
arr[0] = z;
z[0] = 3;
assert(arr[0][0] == 3);
return true;
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail77.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ void test()
{
int i;
ubyte[4] ub;
ub[] = (cast(ubyte[4]) &i)[];
ub[] = cast(ubyte[4]) &i;
//ub[] = (cast(ubyte*) &i)[0..4];
}

57 changes: 57 additions & 0 deletions test/fail_compilation/warn7444.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// REQUIRED_ARGS: -w
// PERMUTE_ARGS:

/*
TEST_OUTPUT:
---
fail_compilation/warn7444.d(30): Warning: explicit element-wise assignment (sa)[] = e is better than sa = e
fail_compilation/warn7444.d(32): Error: cannot implicitly convert expression (e) of type int to int[]
fail_compilation/warn7444.d(37): Warning: explicit element-wise assignment (sa)[] = sa[] is better than sa = sa[]
fail_compilation/warn7444.d(38): Warning: explicit element-wise assignment sa[] = (sa)[] is better than sa[] = sa
fail_compilation/warn7444.d(41): Warning: explicit element-wise assignment (sa)[] = (da)[] is better than sa = da
fail_compilation/warn7444.d(42): Warning: explicit element-wise assignment (sa)[] = da[] is better than sa = da[]
fail_compilation/warn7444.d(43): Warning: explicit element-wise assignment sa[] = (da)[] is better than sa[] = da
fail_compilation/warn7444.d(47): Warning: explicit slice assignment da = (sa)[] is better than da = sa
fail_compilation/warn7444.d(49): Warning: explicit element-wise assignment da[] = (sa)[] is better than da[] = sa
fail_compilation/warn7444.d(54): Warning: explicit element-wise assignment da[] = (da)[] is better than da[] = da
---
*/

void test7444()
{
int[2] sa;
int[] da;
int e;

{
// X: Changed accepts-invalid to rejects-invalid by this issue
// a: slice assginment
// b: element-wise assignment
sa = e; // X
sa[] = e; // b
da = e;
da[] = e; // b

// lhs is static array
sa = sa; // b == identity assign
sa = sa[]; // X
sa[] = sa; // X
sa[] = sa[]; // b

sa = da; // X
sa = da[]; // X
sa[] = da; // X
sa[] = da[]; // b

// lhs is dynamic array
da = sa; // X
da = sa[]; // a
da[] = sa; // X
da[] = sa[]; // b

da = da; // a == identity assign
da = da[]; // a
da[] = da; // X
da[] = da[]; // b
}
}
Loading

0 comments on commit 8519a3a

Please sign in to comment.