Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 7922 - alias this causes weird formatting issues for strings #885

Merged
merged 1 commit into from about 2 years ago

2 participants

Hara Kenji Walter Bright
Hara Kenji
Collaborator
9rnsr commented

This was a regression of fixing 7583, and redundant copy of syntax tree have been made this problem.
So I revert efd4711 + cd7dfca, and add necessary and sufficient copy.

k-hara fix Issue 7922 - alias this causes weird formatting issues for strings
This was a regression of fixing 7583, and redundant copy of syntax tree have been made this problem.
So I revert efd4711 + cd7dfca, and add necessary and sufficient copy.
a235ba4
Walter Bright WalterBright merged commit 3ecc1f3 into from
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user 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

Showing 1 unique commit by 1 author.

Apr 30, 2012
k-hara fix Issue 7922 - alias this causes weird formatting issues for strings
This was a regression of fixing 7583, and redundant copy of syntax tree have been made this problem.
So I revert efd4711 + cd7dfca, and add necessary and sufficient copy.
a235ba4
This page is out of date. Refresh to see the latest.

Showing 3 changed files with 79 additions and 30 deletions. Show diff stats Hide diff stats

  1. +9 3 src/declaration.c
  2. +45 27 src/opover.c
  3. +25 0 test/runnable/aliasthis.d
12 src/declaration.c
@@ -1373,11 +1373,17 @@ void VarDeclaration::semantic(Scope *sc)
1373 1373 e->op = TOKblit;
1374 1374 }
1375 1375 e->type = t;
1376   - (*pinit) = new CommaExp(loc, e, (*pinit));
1377 1376
1378   - /* Replace __ctmp being constructed with e1
  1377 + /* Replace __ctmp being constructed with e1.
  1378 + * We need to copy constructor call expression,
  1379 + * because it may be used in other place.
1379 1380 */
1380   - dve->e1 = e1;
  1381 + DotVarExp *dvx = (DotVarExp *)dve->copy();
  1382 + dvx->e1 = e1;
  1383 + CallExp *cx = (CallExp *)ce->copy();
  1384 + cx->e1 = dvx;
  1385 +
  1386 + (*pinit) = new CommaExp(loc, e, cx);
1381 1387 (*pinit) = (*pinit)->semantic(sc);
1382 1388 goto Ldtor;
1383 1389 }
72 src/opover.c
@@ -354,9 +354,11 @@ Expression *UnaExp::op_overload(Scope *sc)
354 354 /* Rewrite op(e1) as:
355 355 * op(e1.aliasthis)
356 356 */
357   - UnaExp *e = (UnaExp *)syntaxCopy();
358   - e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
359   - return e->trySemantic(sc);
  357 + Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
  358 + Expression *e = copy();
  359 + ((UnaExp *)e)->e1 = e1;
  360 + e = e->trySemantic(sc);
  361 + return e;
360 362 }
361 363 #endif
362 364 }
@@ -411,9 +413,11 @@ Expression *ArrayExp::op_overload(Scope *sc)
411 413 /* Rewrite op(e1) as:
412 414 * op(e1.aliasthis)
413 415 */
414   - UnaExp *e = (UnaExp *)syntaxCopy();
415   - e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
416   - return e->trySemantic(sc);
  416 + Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
  417 + Expression *e = copy();
  418 + ((UnaExp *)e)->e1 = e1;
  419 + e = e->trySemantic(sc);
  420 + return e;
417 421 }
418 422 }
419 423 return NULL;
@@ -456,9 +460,11 @@ Expression *CastExp::op_overload(Scope *sc)
456 460 /* Rewrite op(e1) as:
457 461 * op(e1.aliasthis)
458 462 */
459   - UnaExp *e = (UnaExp *)syntaxCopy();
460   - e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
461   - return e->trySemantic(sc);
  463 + Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
  464 + Expression *e = copy();
  465 + ((UnaExp *)e)->e1 = e1;
  466 + e = e->trySemantic(sc);
  467 + return e;
462 468 }
463 469 }
464 470 return NULL;
@@ -714,9 +720,11 @@ Expression *BinExp::op_overload(Scope *sc)
714 720 /* Rewrite (e1 op e2) as:
715 721 * (e1.aliasthis op e2)
716 722 */
717   - BinExp *e = (BinExp *)syntaxCopy();
718   - e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
719   - return e->trySemantic(sc);
  723 + Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
  724 + Expression *e = copy();
  725 + ((BinExp *)e)->e1 = e1;
  726 + e = e->trySemantic(sc);
  727 + return e;
720 728 }
721 729
722 730 // Try alias this on second operand
@@ -729,9 +737,11 @@ Expression *BinExp::op_overload(Scope *sc)
729 737 /* Rewrite (e1 op e2) as:
730 738 * (e1 op e2.aliasthis)
731 739 */
732   - BinExp *e = (BinExp *)syntaxCopy();
733   - e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
734   - return e->trySemantic(sc);
  740 + Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
  741 + Expression *e = copy();
  742 + ((BinExp *)e)->e2 = e2;
  743 + e = e->trySemantic(sc);
  744 + return e;
735 745 }
736 746 #endif
737 747 return NULL;
@@ -883,9 +893,11 @@ Expression *BinExp::compare_overload(Scope *sc, Identifier *id)
883 893 /* Rewrite (e1 op e2) as:
884 894 * (e1.aliasthis op e2)
885 895 */
886   - BinExp *e = (BinExp *)syntaxCopy();
887   - e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
888   - return e->trySemantic(sc);
  896 + Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
  897 + Expression *e = copy();
  898 + ((BinExp *)e)->e1 = e1;
  899 + e = e->trySemantic(sc);
  900 + return e;
889 901 }
890 902
891 903 // Try alias this on second operand
@@ -894,9 +906,11 @@ Expression *BinExp::compare_overload(Scope *sc, Identifier *id)
894 906 /* Rewrite (e1 op e2) as:
895 907 * (e1 op e2.aliasthis)
896 908 */
897   - BinExp *e = (BinExp *)syntaxCopy();
898   - e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
899   - return e->trySemantic(sc);
  909 + Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
  910 + Expression *e = copy();
  911 + ((BinExp *)e)->e2 = e2;
  912 + e = e->trySemantic(sc);
  913 + return e;
900 914 }
901 915
902 916 return NULL;
@@ -1131,9 +1145,11 @@ Expression *BinAssignExp::op_overload(Scope *sc)
1131 1145 /* Rewrite (e1 op e2) as:
1132 1146 * (e1.aliasthis op e2)
1133 1147 */
1134   - BinExp *e = (BinExp *)syntaxCopy();
1135   - e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
1136   - return e->trySemantic(sc);
  1148 + Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
  1149 + Expression *e = copy();
  1150 + ((BinExp *)e)->e1 = e1;
  1151 + e = e->trySemantic(sc);
  1152 + return e;
1137 1153 }
1138 1154
1139 1155 // Try alias this on second operand
@@ -1143,9 +1159,11 @@ Expression *BinAssignExp::op_overload(Scope *sc)
1143 1159 /* Rewrite (e1 op e2) as:
1144 1160 * (e1 op e2.aliasthis)
1145 1161 */
1146   - BinExp *e = (BinExp *)syntaxCopy();
1147   - e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
1148   - return e->trySemantic(sc);
  1162 + Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
  1163 + Expression *e = copy();
  1164 + ((BinExp *)e)->e2 = e2;
  1165 + e = e->trySemantic(sc);
  1166 + return e;
1149 1167 }
1150 1168 #endif
1151 1169 return NULL;
25 test/runnable/aliasthis.d
... ... @@ -1,5 +1,6 @@
1 1
2 2 extern (C) int printf(const(char*) fmt, ...);
  3 +import core.vararg;
3 4
4 5 struct Tup(T...)
5 6 {
@@ -810,6 +811,29 @@ void test7945()
810 811 }
811 812
812 813 /***************************************************/
  814 +// 7992
  815 +
  816 +struct S7992
  817 +{
  818 + int[] arr;
  819 + alias arr this;
  820 +}
  821 +S7992 func7992(...)
  822 +{
  823 + S7992 ret;
  824 + ret.arr.length = _arguments.length;
  825 + return ret;
  826 +}
  827 +void test7992()
  828 +{
  829 + int[] arr;
  830 + assert(arr.length == 0);
  831 + arr ~= func7992(1, 2); //NG
  832 + //arr = func7992(1, 2); //OK
  833 + assert(arr.length == 2);
  834 +}
  835 +
  836 +/***************************************************/
813 837
814 838 int main()
815 839 {
@@ -841,6 +865,7 @@ int main()
841 865 test7731();
842 866 test7808();
843 867 test7945();
  868 + test7992();
844 869
845 870 printf("Success\n");
846 871 return 0;

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.