about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-01-10 15:59:22 -0800
committerGraydon Hoare <graydon@mozilla.com>2012-01-10 15:59:57 -0800
commit0e334c6839566dfa7d173ce6a4f83d672d223114 (patch)
treed8137d56f4c5450824866e5e1ca9e17e7ebd093c /src/comp
parent1dc3debdafbf29c6ac4ff3cf336da62e13e1871e (diff)
downloadrust-0e334c6839566dfa7d173ce6a4f83d672d223114.tar.gz
rust-0e334c6839566dfa7d173ce6a4f83d672d223114.zip
Fold and re-evaluate expr in tag discriminant.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/syntax/fold.rs19
-rw-r--r--src/comp/syntax/parse/parser.rs2
2 files changed, 17 insertions, 4 deletions
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index 70f8d7e3406..f075979b7f6 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -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; }
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index a27209424ae..c3fb803e489 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -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