aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-08 13:00:31 -0800
committerPatrick Walton <[email protected]>2011-03-08 13:00:31 -0800
commit35bee753dea812bb8112c5bf5c02e1311bbca2fa (patch)
tree94f4949ba5a65a56633e374aee0e1851b4f42ffc /src
parentrustc: Add a slot for explicit type parameter instantations to the typechecke... (diff)
downloadrust-35bee753dea812bb8112c5bf5c02e1311bbca2fa.tar.xz
rust-35bee753dea812bb8112c5bf5c02e1311bbca2fa.zip
rustc: Pass explicit type substitutions to later passes
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/typeck.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index cf917d19..15383020 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -86,11 +86,11 @@ fn generalize_ty(@crate_ctxt cx, @ty.t t) -> @ty.t {
fn substitute_ty_params(&@crate_ctxt ccx,
@ty.t typ,
vec[ast.def_id] ty_params,
- vec[@ast.ty] supplied,
+ vec[@ty.t] supplied,
&span sp) -> @ty.t {
state obj ty_substituter(@crate_ctxt ccx,
vec[ast.def_id] ty_params,
- vec[@ast.ty] supplied) {
+ vec[@ty.t] supplied) {
fn fold_simple_ty(@ty.t typ) -> @ty.t {
alt (typ.struct) {
case (ty.ty_param(?pid)) {
@@ -108,7 +108,7 @@ fn substitute_ty_params(&@crate_ctxt ccx,
}
// Substitute it in.
- ret ast_ty_to_ty_crate(ccx, supplied.(i));
+ ret supplied.(i);
}
case (_) { ret typ; }
}
@@ -116,7 +116,7 @@ fn substitute_ty_params(&@crate_ctxt ccx,
}
auto ty_param_len = _vec.len[ast.def_id](ty_params);
- auto supplied_len = _vec.len[@ast.ty](supplied);
+ auto supplied_len = _vec.len[@ty.t](supplied);
if (ty_param_len != supplied_len) {
ccx.sess.span_err(sp, "expected " + _uint.to_str(ty_param_len, 10u) +
" type parameter(s) but found " +
@@ -1564,19 +1564,33 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
// Substitute type parameters if the user provided some.
- if (_vec.len[@ast.ty](pth.node.types) > 0u) {
+ auto ty_substs_opt;
+ auto ty_substs_len = _vec.len[@ast.ty](pth.node.types);
+ if (ty_substs_len > 0u) {
+ let vec[@ty.t] ty_substs = vec();
+ auto i = 0u;
+ while (i < ty_substs_len) {
+ ty_substs += vec(ast_ty_to_ty_crate(fcx.ccx,
+ pth.node.types.(i)));
+ i += 1u;
+ }
+ ty_substs_opt = some[vec[@ty.t]](ty_substs);
+
alt (ty_params) {
case (none[vec[ast.def_id]]) {
fcx.ccx.sess.span_err(expr.span, "this kind of " +
"item may not take type " +
"parameters");
+ fail;
}
case (some[vec[ast.def_id]](?tps)) {
- t = substitute_ty_params(fcx.ccx, t, tps,
- pth.node.types, expr.span);
+ t = substitute_ty_params(fcx.ccx, t, tps, ty_substs,
+ expr.span);
}
}
} else {
+ ty_substs_opt = none[vec[@ty.t]];
+
alt (ty_params) {
case (none[vec[ast.def_id]]) { /* nothing */ }
case (some[vec[ast.def_id]](_)) {
@@ -1587,7 +1601,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
}
- auto ann = ast.ann_type(t, none[vec[@ty.t]]);
+ auto ann = ast.ann_type(t, ty_substs_opt);
ret @fold.respan[ast.expr_](expr.span,
ast.expr_path(pth, defopt, ann));
}