Revert "rustc: Push type parameters down through alt tag patterns; add a test" due to valgrind failures
This reverts commit 7a1d01effc.
This commit is contained in:
parent
7a6ac1c000
commit
6c24d0403b
2 changed files with 11 additions and 68 deletions
|
|
@ -913,43 +913,15 @@ fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
|
|||
// of the variant, which is either a tag type in the case of
|
||||
// nullary variants or a function type in the case of n-ary
|
||||
// variants.
|
||||
//
|
||||
// TODO: When we have type-parametric tags, this will get a little
|
||||
// trickier. Basically, we have to instantiate the variant type we
|
||||
// acquire here with the type parameters provided to us by
|
||||
// "expected".
|
||||
|
||||
// Grab the values for the type parameters of the tag from the
|
||||
// expected type.
|
||||
let vec[@ty.t] typaram_bindings = vec(); // FIXME: typestate botch
|
||||
alt (expected.struct) {
|
||||
case (ty.ty_tag(_, ?tps)) { typaram_bindings = tps; }
|
||||
case (_) {
|
||||
log "tag pattern didn't have tag type?!";
|
||||
fail;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the item corresponding to the tag and its type.
|
||||
auto vdef = option.get[ast.variant_def](vdef_opt);
|
||||
auto variant_ty = fcx.ccx.item_types.get(vdef._1);
|
||||
|
||||
// FIXME: typestate botch
|
||||
let option.t[@ast.item] item_opt = none[@ast.item];
|
||||
alt (fcx.ccx.item_items.get(vdef._0)) {
|
||||
case (any_item_rust(?it)) { item_opt = some[@ast.item](it); }
|
||||
case (_) {
|
||||
log "tag item isn't a Rust item?!";
|
||||
fail;
|
||||
}
|
||||
}
|
||||
let @ast.item item = option.get[@ast.item](item_opt);
|
||||
|
||||
// Get the IDs of the type parameters from that item.
|
||||
let vec[ast.ty_param] ty_params = vec(); // FIXME: typestate botch
|
||||
alt (item.node) {
|
||||
case (ast.item_tag(_, _, ?tps, _)) { ty_params = tps; }
|
||||
case (_) {
|
||||
log "tag's corresponding item isn't a tag?!";
|
||||
fail;
|
||||
}
|
||||
}
|
||||
|
||||
auto subpats_len = _vec.len[@ast.pat](subpats);
|
||||
alt (variant_ty.struct) {
|
||||
case (ty.ty_tag(_, _)) {
|
||||
|
|
@ -958,14 +930,10 @@ fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
|
|||
p_1 = ast.pat_tag(id, subpats, vdef_opt, ast.ann_type(t));
|
||||
}
|
||||
case (ty.ty_fn(_, ?args, ?tag_ty)) {
|
||||
// N-ary tag variant.
|
||||
let vec[@ast.pat] new_subpats = vec();
|
||||
auto i = 0u;
|
||||
for (arg a in args) {
|
||||
auto arg_ty = ty.substitute_ty_params(ty_params,
|
||||
typaram_bindings, a.ty);
|
||||
auto new_subpat = demand_pat(fcx, arg_ty,
|
||||
subpats.(i));
|
||||
auto new_subpat = demand_pat(fcx, a.ty, subpats.(i));
|
||||
new_subpats += vec(new_subpat);
|
||||
i += 1u;
|
||||
}
|
||||
|
|
@ -1292,13 +1260,14 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
|
|||
new_subpats += vec(check_pat(fcx, subpat));
|
||||
}
|
||||
|
||||
auto tag_ty_g = generalize_ty(fcx.ccx, tag_ty);
|
||||
auto ann = ast.ann_type(tag_ty_g);
|
||||
auto ann = ast.ann_type(tag_ty);
|
||||
new_pat = ast.pat_tag(p, new_subpats, vdef_opt, ann);
|
||||
}
|
||||
|
||||
// Nullary variants have tag types.
|
||||
case (ty.ty_tag(?tid, ?tps)) {
|
||||
case (ty.ty_tag(?tid, _)) {
|
||||
// TODO: ty params
|
||||
|
||||
auto subpats_len = _vec.len[@ast.pat](subpats);
|
||||
if (subpats_len > 0u) {
|
||||
// TODO: pluralize properly
|
||||
|
|
@ -1312,14 +1281,7 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
|
|||
fail; // TODO: recover
|
||||
}
|
||||
|
||||
// Add the appropriate number of type variables.
|
||||
let vec[@ty.t] tys = vec();
|
||||
auto i = 0u;
|
||||
while (i < _vec.len[@ty.t](tps)) {
|
||||
tys += vec(next_ty_var(fcx.ccx));
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
let vec[@ty.t] tys = vec(); // FIXME
|
||||
auto ann = ast.ann_type(plain_ty(ty.ty_tag(tid, tys)));
|
||||
new_pat = ast.pat_tag(p, subpats, vdef_opt, ann);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
tag foo[T] {
|
||||
arm(@T);
|
||||
}
|
||||
|
||||
fn altfoo[T](foo[T] f) {
|
||||
auto hit = false;
|
||||
alt (f) {
|
||||
case (arm[T](?x)) {
|
||||
log "in arm";
|
||||
hit = true;
|
||||
}
|
||||
}
|
||||
check (hit);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
altfoo[int](arm[int](@10));
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue