Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #885 from 9rnsr/fix7922

Issue 7922 - alias this causes weird formatting issues for strings
  • Loading branch information...
commit 3ecc1f3fbfd1d821bd647bde2e9d4adbcf9f2b9d 2 parents ad84e0d + a235ba4
@WalterBright WalterBright authored
Showing with 79 additions and 30 deletions.
  1. +9 −3 src/declaration.c
  2. +45 −27 src/opover.c
  3. +25 −0 test/runnable/aliasthis.d
View
12 src/declaration.c
@@ -1386,11 +1386,17 @@ void VarDeclaration::semantic(Scope *sc)
e->op = TOKblit;
}
e->type = t;
- (*pinit) = new CommaExp(loc, e, (*pinit));
- /* Replace __ctmp being constructed with e1
+ /* Replace __ctmp being constructed with e1.
+ * We need to copy constructor call expression,
+ * because it may be used in other place.
*/
- dve->e1 = e1;
+ DotVarExp *dvx = (DotVarExp *)dve->copy();
+ dvx->e1 = e1;
+ CallExp *cx = (CallExp *)ce->copy();
+ cx->e1 = dvx;
+
+ (*pinit) = new CommaExp(loc, e, cx);
(*pinit) = (*pinit)->semantic(sc);
goto Ldtor;
}
View
72 src/opover.c
@@ -355,9 +355,11 @@ Expression *UnaExp::op_overload(Scope *sc)
/* Rewrite op(e1) as:
* op(e1.aliasthis)
*/
- UnaExp *e = (UnaExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
+ Expression *e = copy();
+ ((UnaExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
#endif
}
@@ -412,9 +414,11 @@ Expression *ArrayExp::op_overload(Scope *sc)
/* Rewrite op(e1) as:
* op(e1.aliasthis)
*/
- UnaExp *e = (UnaExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
+ Expression *e = copy();
+ ((UnaExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
}
return NULL;
@@ -457,9 +461,11 @@ Expression *CastExp::op_overload(Scope *sc)
/* Rewrite op(e1) as:
* op(e1.aliasthis)
*/
- UnaExp *e = (UnaExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident);
+ Expression *e = copy();
+ ((UnaExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
}
return NULL;
@@ -715,9 +721,11 @@ Expression *BinExp::op_overload(Scope *sc)
/* Rewrite (e1 op e2) as:
* (e1.aliasthis op e2)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
// Try alias this on second operand
@@ -730,9 +738,11 @@ Expression *BinExp::op_overload(Scope *sc)
/* Rewrite (e1 op e2) as:
* (e1 op e2.aliasthis)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e2 = e2;
+ e = e->trySemantic(sc);
+ return e;
}
#endif
return NULL;
@@ -884,9 +894,11 @@ Expression *BinExp::compare_overload(Scope *sc, Identifier *id)
/* Rewrite (e1 op e2) as:
* (e1.aliasthis op e2)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
// Try alias this on second operand
@@ -895,9 +907,11 @@ Expression *BinExp::compare_overload(Scope *sc, Identifier *id)
/* Rewrite (e1 op e2) as:
* (e1 op e2.aliasthis)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e2 = e2;
+ e = e->trySemantic(sc);
+ return e;
}
return NULL;
@@ -1132,9 +1146,11 @@ Expression *BinAssignExp::op_overload(Scope *sc)
/* Rewrite (e1 op e2) as:
* (e1.aliasthis op e2)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e1 = new DotIdExp(loc, e->e1, ad1->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e1 = e1;
+ e = e->trySemantic(sc);
+ return e;
}
// Try alias this on second operand
@@ -1144,9 +1160,11 @@ Expression *BinAssignExp::op_overload(Scope *sc)
/* Rewrite (e1 op e2) as:
* (e1 op e2.aliasthis)
*/
- BinExp *e = (BinExp *)syntaxCopy();
- e->e2 = new DotIdExp(loc, e->e2, ad2->aliasthis->ident);
- return e->trySemantic(sc);
+ Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident);
+ Expression *e = copy();
+ ((BinExp *)e)->e2 = e2;
+ e = e->trySemantic(sc);
+ return e;
}
#endif
return NULL;
View
25 test/runnable/aliasthis.d
@@ -1,5 +1,6 @@
extern (C) int printf(const(char*) fmt, ...);
+import core.vararg;
struct Tup(T...)
{
@@ -810,6 +811,29 @@ void test7945()
}
/***************************************************/
+// 7992
+
+struct S7992
+{
+ int[] arr;
+ alias arr this;
+}
+S7992 func7992(...)
+{
+ S7992 ret;
+ ret.arr.length = _arguments.length;
+ return ret;
+}
+void test7992()
+{
+ int[] arr;
+ assert(arr.length == 0);
+ arr ~= func7992(1, 2); //NG
+ //arr = func7992(1, 2); //OK
+ assert(arr.length == 2);
+}
+
+/***************************************************/
int main()
{
@@ -841,6 +865,7 @@ int main()
test7731();
test7808();
test7945();
+ test7992();
printf("Success\n");
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.