Skip to content

Commit

Permalink
Make class this and super rvalues.
Browse files Browse the repository at this point in the history
  • Loading branch information
H. S. Teoh committed Jul 14, 2014
1 parent d182caf commit 7560a29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/expression.c
Expand Up @@ -3455,22 +3455,18 @@ int ThisExp::isBool(int result)

int ThisExp::isLvalue()
{
return 1;
// Class `this` is an rvalue; struct `this` is an lvalue.
return (type->toBasetype()->ty != Tclass);
}

Expression *ThisExp::toLvalue(Scope *sc, Expression *e)
{
return this;
}

Expression *ThisExp::modifiableLvalue(Scope *sc, Expression *e)
{
if (type->toBasetype()->ty == Tclass)
{
error("cannot modify '%s' reference", toChars());
return toLvalue(sc, e);
// Class `this` is an rvalue; struct `this` is an lvalue.
return Expression::toLvalue(sc, e);
}
return Expression::modifiableLvalue(sc, e);
return this;
}

/******************************** SuperExp **************************/
Expand Down
1 change: 0 additions & 1 deletion src/expression.h
Expand Up @@ -367,7 +367,6 @@ class ThisExp : public Expression
int isBool(int result);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);

void accept(Visitor *v) { v->visit(this); }
};
Expand Down

0 comments on commit 7560a29

Please sign in to comment.