Skip to content

Commit e8e3db8

Browse files
committed
---
yaml --- r: 1553 b: refs/heads/master c: 35bee75 h: refs/heads/master i: 1551: f06bc5a v: v3
1 parent 75fdbff commit e8e3db8

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4654faa67c831728c677027f2beb48fe3592b511
2+
refs/heads/master: 35bee753dea812bb8112c5bf5c02e1311bbca2fa

trunk/src/comp/middle/typeck.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ fn generalize_ty(@crate_ctxt cx, @ty.t t) -> @ty.t {
8686
fn substitute_ty_params(&@crate_ctxt ccx,
8787
@ty.t typ,
8888
vec[ast.def_id] ty_params,
89-
vec[@ast.ty] supplied,
89+
vec[@ty.t] supplied,
9090
&span sp) -> @ty.t {
9191
state obj ty_substituter(@crate_ctxt ccx,
9292
vec[ast.def_id] ty_params,
93-
vec[@ast.ty] supplied) {
93+
vec[@ty.t] supplied) {
9494
fn fold_simple_ty(@ty.t typ) -> @ty.t {
9595
alt (typ.struct) {
9696
case (ty.ty_param(?pid)) {
@@ -108,15 +108,15 @@ fn substitute_ty_params(&@crate_ctxt ccx,
108108
}
109109

110110
// Substitute it in.
111-
ret ast_ty_to_ty_crate(ccx, supplied.(i));
111+
ret supplied.(i);
112112
}
113113
case (_) { ret typ; }
114114
}
115115
}
116116
}
117117

118118
auto ty_param_len = _vec.len[ast.def_id](ty_params);
119-
auto supplied_len = _vec.len[@ast.ty](supplied);
119+
auto supplied_len = _vec.len[@ty.t](supplied);
120120
if (ty_param_len != supplied_len) {
121121
ccx.sess.span_err(sp, "expected " + _uint.to_str(ty_param_len, 10u) +
122122
" type parameter(s) but found " +
@@ -1564,19 +1564,33 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
15641564
}
15651565

15661566
// Substitute type parameters if the user provided some.
1567-
if (_vec.len[@ast.ty](pth.node.types) > 0u) {
1567+
auto ty_substs_opt;
1568+
auto ty_substs_len = _vec.len[@ast.ty](pth.node.types);
1569+
if (ty_substs_len > 0u) {
1570+
let vec[@ty.t] ty_substs = vec();
1571+
auto i = 0u;
1572+
while (i < ty_substs_len) {
1573+
ty_substs += vec(ast_ty_to_ty_crate(fcx.ccx,
1574+
pth.node.types.(i)));
1575+
i += 1u;
1576+
}
1577+
ty_substs_opt = some[vec[@ty.t]](ty_substs);
1578+
15681579
alt (ty_params) {
15691580
case (none[vec[ast.def_id]]) {
15701581
fcx.ccx.sess.span_err(expr.span, "this kind of " +
15711582
"item may not take type " +
15721583
"parameters");
1584+
fail;
15731585
}
15741586
case (some[vec[ast.def_id]](?tps)) {
1575-
t = substitute_ty_params(fcx.ccx, t, tps,
1576-
pth.node.types, expr.span);
1587+
t = substitute_ty_params(fcx.ccx, t, tps, ty_substs,
1588+
expr.span);
15771589
}
15781590
}
15791591
} else {
1592+
ty_substs_opt = none[vec[@ty.t]];
1593+
15801594
alt (ty_params) {
15811595
case (none[vec[ast.def_id]]) { /* nothing */ }
15821596
case (some[vec[ast.def_id]](_)) {
@@ -1587,7 +1601,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
15871601
}
15881602
}
15891603

1590-
auto ann = ast.ann_type(t, none[vec[@ty.t]]);
1604+
auto ann = ast.ann_type(t, ty_substs_opt);
15911605
ret @fold.respan[ast.expr_](expr.span,
15921606
ast.expr_path(pth, defopt, ann));
15931607
}

0 commit comments

Comments
 (0)