Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Regression 7493 Initialization of void[][N] #866

Merged
merged 2 commits into from

3 participants

@donc
Collaborator

Make it so that:

void []...[N] arr = foo

is never a block assignment, except for the necessary:

void []...[N] arr = null

Ie, foo must always be an array of length N with members that implicitly convert to void[]...
I think this is the most defensible and predictable semantics for this bizarre corner case.
However, note that the spec doesn't mention block assignment at all.

@WalterBright WalterBright merged commit eb7a044 into D-Programming-Language:master
@WalterBright WalterBright referenced this pull request from a commit
@WalterBright WalterBright merge D2 pull #866 ffa2673
@braddr braddr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. @don-clugston-sociomantic
  2. @don-clugston-sociomantic

    Fix dangling else in test suite

    don-clugston-sociomantic authored
    This test didn't compile with -w
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 7 deletions.
  1. +9 −1 src/expression.c
  2. +21 −6 test/runnable/test20.d
View
10 src/expression.c
@@ -10365,8 +10365,16 @@ Expression *AssignExp::semantic(Scope *sc)
}
else
#endif
+ // If it is a array, get the element type. Note that it may be
+ // multi-dimensional.
+ Type *telem = t1;
+ while (telem->ty == Tarray)
+ telem = telem->nextOf();
+
+ // Check for block assignment. If it is of type void[], void[][], etc,
+ // '= null' is the only allowable block assignment (Bug 7493)
if (e1->op == TOKslice &&
- t1->nextOf() &&
+ t1->nextOf() && (telem->ty != Tvoid || e2->op == TOKnull) &&
e2->implicitConvTo(t1->nextOf())
)
{ // memset
View
27 test/runnable/test20.d
@@ -860,15 +860,17 @@ template pow(F)
if (i < 1)
{
static if (is(F : real))
- return 1;
+ return 1;
else
- return F(1);
+ return F(1);
}
if (i & 1)
- if(i == 1)
- return x;
- else
- return x * pow(x,i-1);
+ {
+ if (i == 1)
+ return x;
+ else
+ return x * pow(x,i-1);
+ }
return sqr!(F)(pow(x,i/2));
}
}
@@ -1254,6 +1256,18 @@ void test61()
/*****************************************/
+void bug7493()
+{
+ string str = "abcde";
+ const(void) [][1] arr = [str];
+ assert(arr[0].length == str.length);
+ const(void) [][1] arr2;
+ arr2 = [str];
+ assert(arr[0].length == str.length);
+}
+
+/*****************************************/
+
int main()
{
test1();
@@ -1314,6 +1328,7 @@ int main()
test59();
test60();
test61();
+ bug7493();
printf("Success\n");
return 0;
Something went wrong with that request. Please try again.