Skip to content

Commit

Permalink
Fix CallExp and AssignExp
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 21, 2013
1 parent de754dd commit 460c512
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/expression.c
Expand Up @@ -8066,8 +8066,10 @@ Expression *CallExp::semantic(Scope *sc)

if (e1->op != TOKtype)
{
if (ad->aliasthis)
if (ad->aliasthis && e1->type != att1)
{
if (!att1 && e1->type->checkAliasThisRec())
att1 = e1->type;
e1 = resolveAliasThis(sc, e1);
goto Lagain;
}
Expand Down Expand Up @@ -10390,6 +10392,7 @@ Expression *AssignExp::semantic(Scope *sc)

ae->e1 = ae->e1->semantic(sc);
ae->e1 = resolveProperties(sc, ae->e1);
Expression *e1 = ae->e1;
Type *t1 = ae->e1->type->toBasetype();
if (t1->ty == Tstruct)
{
Expand All @@ -10408,26 +10411,28 @@ Expression *AssignExp::semantic(Scope *sc)
Expressions *a = (Expressions *)ae->arguments->copy();
a->insert(0, e2);

Expression *e = new DotIdExp(loc, ae->e1, Id::indexass);
Expression *e = new DotIdExp(loc, e1, Id::indexass);
e = new CallExp(loc, e, a);
e = e->semantic(sc);
return e;
}
}

// No opIndexAssign found yet, but there might be an alias this to try.
if (ad && ad->aliasthis)
{ Expression *e = resolveAliasThis(sc, ae->e1);
Type *t = e->type->toBasetype();

if (t->ty == Tstruct)
if (ad && ad->aliasthis && t1 != att1)
{
if (!att1 && t1->checkAliasThisRec())
att1 = t1;
e1 = resolveAliasThis(sc, e1);
t1 = e1->type->toBasetype();
if (t1->ty == Tstruct)
{
ad = ((TypeStruct *)t)->sym;
ad = ((TypeStruct *)t1)->sym;
goto L1;
}
else if (t->ty == Tclass)
else if (t1->ty == Tclass)
{
ad = ((TypeClass *)t)->sym;
ad = ((TypeClass *)t1)->sym;
goto L1;
}
}
Expand All @@ -10437,14 +10442,15 @@ Expression *AssignExp::semantic(Scope *sc)
* converted to a.opSlice() already.
*/
if (e1->op == TOKslice)
{ Type *t1;
{
SliceExp *ae = (SliceExp *)e1;
AggregateDeclaration *ad = NULL;
Identifier *id = Id::index;

ae->e1 = ae->e1->semantic(sc);
ae->e1 = resolveProperties(sc, ae->e1);
t1 = ae->e1->type->toBasetype();
Expression *e1 = ae->e1;
Type *t1 = ae->e1->type->toBasetype();
if (t1->ty == Tstruct)
{
ad = ((TypeStruct *)t1)->sym;
Expand All @@ -10465,26 +10471,28 @@ Expression *AssignExp::semantic(Scope *sc)
{ a->push(ae->lwr);
a->push(ae->upr);
}
Expression *e = new DotIdExp(loc, ae->e1, Id::sliceass);
Expression *e = new DotIdExp(loc, e1, Id::sliceass);
e = new CallExp(loc, e, a);
e = e->semantic(sc);
return e;
}
}

// No opSliceAssign found yet, but there might be an alias this to try.
if (ad && ad->aliasthis)
{ Expression *e = resolveAliasThis(sc, ae->e1);
Type *t = e->type->toBasetype();

if (t->ty == Tstruct)
if (ad && ad->aliasthis && t1 != att1)
{
if (!att1 && t1->checkAliasThisRec())
att1 = t1;
e1 = resolveAliasThis(sc, e1);
t1 = e1->type->toBasetype();
if (t1->ty == Tstruct)
{
ad = ((TypeStruct *)t)->sym;
ad = ((TypeStruct *)t1)->sym;
goto L2;
}
else if (t->ty == Tclass)
else if (t1->ty == Tclass)
{
ad = ((TypeClass *)t)->sym;
ad = ((TypeClass *)t1)->sym;
goto L2;
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/runnable/aliasthis.d
Expand Up @@ -255,6 +255,22 @@ void test7()
static assert(!__traits(compiles, s1[]));
static assert(!__traits(compiles, s3[]));

// CallExp::semantic
// static assert(!__traits(compiles, c1()));
// static assert(!__traits(compiles, c3()));
static assert(!__traits(compiles, s1()));
static assert(!__traits(compiles, s3()));

// AssignExp::semantic
static assert(!__traits(compiles, { c1[1] = 0; }));
static assert(!__traits(compiles, { c3[1] = 0; }));
static assert(!__traits(compiles, { s1[1] = 0; }));
static assert(!__traits(compiles, { s3[1] = 0; }));
static assert(!__traits(compiles, { c1[ ] = 0; }));
static assert(!__traits(compiles, { c3[ ] = 0; }));
static assert(!__traits(compiles, { s1[ ] = 0; }));
static assert(!__traits(compiles, { s3[ ] = 0; }));

// UnaExp::op_overload
static assert(!__traits(compiles, +c1[1]));
static assert(!__traits(compiles, +c3[1]));
Expand Down

0 comments on commit 460c512

Please sign in to comment.