Fold and re-evaluate expr in tag discriminant.

This commit is contained in:
Graydon Hoare 2012-01-10 15:59:22 -08:00
parent 1dc3debdaf
commit 0e334c6839
2 changed files with 17 additions and 4 deletions

View File

@ -469,9 +469,22 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
ret {ty: fld.fold_ty(va.ty), id: va.id};
}
let fold_variant_arg = bind fold_variant_arg_(_, fld);
ret {name: v.name, args: vec::map(v.args, fold_variant_arg), id: v.id,
disr_val: v.disr_val, disr_expr: v.disr_expr
/* FIXME: is this right (copying disr_val and disr_expr) */};
let args = vec::map(v.args, fold_variant_arg);
let (de, dv) = alt v.disr_expr {
some(e) {
let de = fld.fold_expr(e);
let dv = alt syntax::ast_util::eval_const_expr(e) {
ast_util::const_int(val) {
// FIXME (#1417): check that value is in range
val as int
}
};
(some(de), dv)
}
none. { (none, v.disr_val) }
};
ret {name: v.name, args: args, id: v.id,
disr_val: dv, disr_expr: de};
}
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }

View File

@ -2117,8 +2117,8 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
// probably be doing." (See issue #1417)
alt syntax::ast_util::eval_const_expr(e) {
syntax::ast_util::const_int(val) {
// FIXME (#1417): check that value is in range
disr_val = val as int;
// FIXME: check that value is in range
}
}
if option::is_some