Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 1064 - Tuples are not expanded in array initializers #690

Merged
merged 1 commit into from over 1 year ago

2 participants

Daniel Murphy Hara Kenji
Daniel Murphy
Collaborator

Expand any tuples in place. expandTuples from expression.c cannot be used because this is an array of ExpInitializers, not Expressions.

http://d.puremagic.com/issues/show_bug.cgi?id=1064

Daniel Murphy Issue 1064 - Tuples are not expanded in array initializers
Expand any tuples in place. expandTuples from expression.c cannot be used because this is an array of ExpInitializers, not Expressions.
0e6f621
Hara Kenji 9rnsr merged commit 162cf30 into from July 20, 2012
Hara Kenji 9rnsr closed this July 20, 2012
Hara Kenji
Collaborator
9rnsr commented July 20, 2012

Merged.

Hara Kenji 9rnsr referenced this pull request from a commit in 9rnsr/dmd July 21, 2012
merge D2 pull #690 55bedf4
Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Brad Roberts braddr referenced this pull request from a commit October 21, 2012
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

Showing 1 unique commit by 1 author.

Apr 14, 2012
Daniel Murphy Issue 1064 - Tuples are not expanded in array initializers
Expand any tuples in place. expandTuples from expression.c cannot be used because this is an array of ExpInitializers, not Expressions.
0e6f621
This page is out of date. Refresh to see the latest.
33  src/init.c
@@ -496,8 +496,33 @@ Initializer *ArrayInitializer::semantic(Scope *sc, Type *t, int needInterpret)
496 496
         }
497 497
 
498 498
         Initializer *val = value[i];
  499
+        ExpInitializer *ei = val->isExpInitializer();
  500
+        if (ei && !idx)
  501
+            ei->expandTuples = 1;
499 502
         val = val->semantic(sc, t->nextOf(), needInterpret);
500  
-        value[i] = val;
  503
+
  504
+        ei = val->isExpInitializer();
  505
+        // found a tuple, expand it
  506
+        if (ei && ei->exp->op == TOKtuple)
  507
+        {
  508
+            TupleExp *te = (TupleExp *)ei->exp;
  509
+            index.remove(i);
  510
+            value.remove(i);
  511
+
  512
+            for (size_t j = 0; j < te->exps->dim; ++j)
  513
+            {
  514
+                Expression *e = (*te->exps)[j];
  515
+                index.insert(i + j, (Expression *)NULL);
  516
+                value.insert(i + j, new ExpInitializer(e->loc, e));
  517
+            }
  518
+            i--;
  519
+            continue;
  520
+        }
  521
+        else
  522
+        {
  523
+            value[i] = val;
  524
+        }
  525
+
501 526
         length++;
502 527
         if (length == 0)
503 528
         {   error(loc, "array dimension overflow");
@@ -743,6 +768,7 @@ ExpInitializer::ExpInitializer(Loc loc, Expression *exp)
743 768
     : Initializer(loc)
744 769
 {
745 770
     this->exp = exp;
  771
+    this->expandTuples = 0;
746 772
 }
747 773
 
748 774
 Initializer *ExpInitializer::syntaxCopy()
@@ -827,6 +853,11 @@ Initializer *ExpInitializer::semantic(Scope *sc, Type *t, int needInterpret)
827 853
 
828 854
     Type *tb = t->toBasetype();
829 855
 
  856
+    if (exp->op == TOKtuple &&
  857
+        expandTuples &&
  858
+        !exp->implicitConvTo(t))
  859
+        return new ExpInitializer(loc, exp);
  860
+
830 861
     /* Look for case of initializing a static array with a too-short
831 862
      * string literal, such as:
832 863
      *  char[5] foo = "abc";
1  src/init.h
@@ -114,6 +114,7 @@ struct ArrayInitializer : Initializer
114 114
 struct ExpInitializer : Initializer
115 115
 {
116 116
     Expression *exp;
  117
+    int expandTuples;
117 118
 
118 119
     ExpInitializer(Loc loc, Expression *exp);
119 120
     Initializer *syntaxCopy();
12  test/runnable/xtest46.d
@@ -4033,6 +4033,17 @@ void test4647()
4033 4033
 }
4034 4034
 
4035 4035
 /***************************************************/
  4036
+
  4037
+template T1064(E...) { alias E T1064; }
  4038
+
  4039
+int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ];
  4040
+
  4041
+void test1064()
  4042
+{
  4043
+    assert(var1064 == [1,2,3,4,5,6]);
  4044
+}
  4045
+
  4046
+/***************************************************/
4036 4047
 // 5696
4037 4048
 
4038 4049
 template Seq5696(T...){ alias T Seq5696; }
@@ -5111,6 +5122,7 @@ int main()
5111 5122
     test1891();
5112 5123
     test129();
5113 5124
     test130();
  5125
+    test1064();
5114 5126
     test131();
5115 5127
     test132();
5116 5128
     test133();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.