Merge remote-tracking branch 'origin/topic/jsiwek/bit-1288'

* origin/topic/jsiwek/bit-1288:
  BIT-1288: Improve coercion of &default expressions.

BIT-1288 #merged
This commit is contained in:
Robin Sommer 2014-11-18 11:09:04 -08:00
commit bf35ed699c
7 changed files with 56 additions and 2 deletions

View file

@ -265,6 +265,14 @@ void Attributes::CheckAttr(Attr* a)
// Ok.
break;
Expr* e = a->AttrExpr();
if ( check_and_promote_expr(e, type) )
{
a->SetAttrExpr(e);
// Ok.
break;
}
a->AttrExpr()->Error("&default value has inconsistent type", type);
}
@ -297,8 +305,11 @@ void Attributes::CheckAttr(Attr* a)
Expr* e = a->AttrExpr();
if ( check_and_promote_expr(e, ytype) )
{
a->SetAttrExpr(e);
// Ok.
break;
}
Error("&default value has inconsistent type 2");
}

View file

@ -45,6 +45,13 @@ public:
attr_tag Tag() const { return tag; }
Expr* AttrExpr() const { return expr; }
// Up to the caller to decide if previous expr can be unref'd since it may
// not always be safe; e.g. expressions (at time of writing) don't always
// keep careful track of referencing their operands, so doing something
// like SetAttrExpr(coerce(AttrExpr())) must not completely unref the
// previous expr as the new expr depends on it.
void SetAttrExpr(Expr* e) { expr = e; }
int RedundantAttrOkay() const
{ return tag == ATTR_REDEF || tag == ATTR_OPTIONAL; }