Skip to content

Commit f072358

Browse files
committed
---
yaml --- r: 1557 b: refs/heads/master c: da9ea9a h: refs/heads/master i: 1555: 99d9390 v: v3
1 parent fa1bf97 commit f072358

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 16344a0145555448fc202a2bb8eebd2477dc10b2
2+
refs/heads/master: da9ea9ab69ebcf32ff9cc1ad557a6c2a5134bd0d

trunk/src/comp/middle/trans.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -3083,8 +3083,19 @@ fn lval_generic_fn(@block_ctxt cx,
30833083

30843084
check (cx.fcx.ccx.fn_pairs.contains_key(fn_id));
30853085
auto lv = lval_val(cx, cx.fcx.ccx.fn_pairs.get(fn_id));
3086-
auto monoty = node_ann_type(cx.fcx.ccx, ann);
3087-
auto tys = ty.resolve_ty_params(tpt, monoty);
3086+
3087+
auto monoty;
3088+
auto tys;
3089+
alt (ann) {
3090+
case (ast.ann_none) {
3091+
cx.fcx.ccx.sess.bug("no type annotation for path!");
3092+
fail;
3093+
}
3094+
case (ast.ann_type(?monoty_, ?tps)) {
3095+
monoty = monoty_;
3096+
tys = option.get[vec[@ty.t]](tps);
3097+
}
3098+
}
30883099

30893100
if (_vec.len[@ty.t](tys) != 0u) {
30903101
auto bcx = cx;

trunk/src/comp/middle/typeck.rs

+63-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,37 @@ fn substitute_ty_params(&@crate_ctxt ccx,
128128
ret ty.fold_ty(substituter, typ);
129129
}
130130

131+
// Returns the type parameters and polytype of an item, if it's an item that
132+
// supports type parameters.
133+
fn ty_params_for_item(@crate_ctxt ccx, &ast.def d)
134+
-> option.t[ty.ty_params_and_ty] {
135+
auto params_id;
136+
auto types_id;
137+
alt (d) {
138+
case (ast.def_fn(?id)) { params_id = id; types_id = id; }
139+
case (ast.def_obj(?id)) { params_id = id; types_id = id; }
140+
case (ast.def_obj_field(_)) { ret none[ty.ty_params_and_ty]; }
141+
case (ast.def_mod(_)) { ret none[ty.ty_params_and_ty]; }
142+
case (ast.def_const(_)) { ret none[ty.ty_params_and_ty]; }
143+
case (ast.def_arg(_)) { ret none[ty.ty_params_and_ty]; }
144+
case (ast.def_local(_)) { ret none[ty.ty_params_and_ty]; }
145+
case (ast.def_variant(?tid, ?vid)) {
146+
params_id = tid;
147+
types_id = vid;
148+
}
149+
case (ast.def_ty(_)) { ret none[ty.ty_params_and_ty]; }
150+
case (ast.def_ty_arg(_)) { ret none[ty.ty_params_and_ty]; }
151+
case (ast.def_binding(_)) { ret none[ty.ty_params_and_ty]; }
152+
case (ast.def_use(_)) { ret none[ty.ty_params_and_ty]; }
153+
case (ast.def_native_ty(_)) { ret none[ty.ty_params_and_ty]; }
154+
case (ast.def_native_fn(?id)) { params_id = id; types_id = id; }
155+
}
156+
157+
auto tps = ccx.item_ty_params.get(params_id);
158+
auto polyty = ccx.item_types.get(types_id);
159+
ret some[ty.ty_params_and_ty](tup(tps, polyty));
160+
}
161+
131162
// Parses the programmer's textual representation of a type into our internal
132163
// notion of a type. `getter` is a function that returns the type
133164
// corresponding to a definition ID.
@@ -1190,7 +1221,38 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
11901221
case (ast.expr_path(?pth, ?d, ?ann)) {
11911222
auto t = demand_full(fcx, e.span, expected,
11921223
ann_to_type(ann), adk);
1193-
e_1 = ast.expr_path(pth, d, ast.ann_type(t, none[vec[@ty.t]]));
1224+
1225+
// Fill in the type parameter substitutions if they weren't
1226+
// provided by the programmer.
1227+
auto ty_params_opt;
1228+
alt (ann) {
1229+
case (ast.ann_none) {
1230+
log "demand_expr(): no type annotation for path expr; " +
1231+
"did you pass it to check_expr() first?";
1232+
fail;
1233+
}
1234+
case (ast.ann_type(_, ?tps_opt)) {
1235+
alt (tps_opt) {
1236+
case (none[vec[@ty.t]]) {
1237+
auto defn = option.get[ast.def](d);
1238+
alt (ty_params_for_item(fcx.ccx, defn)) {
1239+
case (none[ty.ty_params_and_ty]) {
1240+
ty_params_opt = none[vec[@ty.t]];
1241+
}
1242+
case (some[ty.ty_params_and_ty](?tpt)) {
1243+
auto tps = ty.resolve_ty_params(tpt, t);
1244+
ty_params_opt = some[vec[@ty.t]](tps);
1245+
}
1246+
}
1247+
}
1248+
case (some[vec[@ty.t]](?tps)) {
1249+
ty_params_opt = some[vec[@ty.t]](tps);
1250+
}
1251+
}
1252+
}
1253+
}
1254+
1255+
e_1 = ast.expr_path(pth, d, ast.ann_type(t, ty_params_opt));
11941256
}
11951257
case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?ann)) {
11961258
auto t = demand_full(fcx, e.span, expected,

0 commit comments

Comments
 (0)