Skip to content

Commit 7a0063b

Browse files
committed
---
yaml --- r: 1567 b: refs/heads/master c: b828ec3 h: refs/heads/master i: 1565: 08f119d 1563: 6bde6d7 1559: 0210d63 1551: f06bc5a 1535: aa3059a v: v3
1 parent d7b3f58 commit 7a0063b

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3c200f3e14ff618431ea12c52031da43ee651984
2+
refs/heads/master: b828ec36fb6d1b6ef5b41d8366287e0b38b4da2e

trunk/src/comp/middle/typeck.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -128,74 +128,77 @@ fn substitute_ty_params(&@crate_ctxt ccx,
128128
ret ty.fold_ty(substituter, typ);
129129
}
130130

131-
// Instantiates the given path, which must refer to an item with the given
132-
// definition.
133-
fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ast.def defn, &span sp)
134-
-> ast.ann {
135-
auto t;
136-
auto ty_params;
131+
type ty_params_opt_and_ty = tup(option.t[vec[ast.def_id]], @ty.t);
132+
133+
// Returns the type parameters and the type for the given definition.
134+
fn ty_params_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
135+
-> ty_params_opt_and_ty {
137136
alt (defn) {
138137
case (ast.def_arg(?id)) {
139138
check (fcx.locals.contains_key(id));
140-
t = fcx.locals.get(id);
141-
ty_params = none[vec[ast.def_id]];
139+
ret tup(none[vec[ast.def_id]], fcx.locals.get(id));
142140
}
143141
case (ast.def_local(?id)) {
142+
auto t;
144143
alt (fcx.locals.find(id)) {
145144
case (some[@ty.t](?t1)) { t = t1; }
146145
case (none[@ty.t]) { t = plain_ty(ty.ty_local(id)); }
147146
}
148-
ty_params = none[vec[ast.def_id]];
147+
ret tup(none[vec[ast.def_id]], t);
149148
}
150149
case (ast.def_obj_field(?id)) {
151150
check (fcx.locals.contains_key(id));
152-
t = fcx.locals.get(id);
153-
ty_params = none[vec[ast.def_id]];
151+
ret tup(none[vec[ast.def_id]], fcx.locals.get(id));
154152
}
155153
case (ast.def_fn(?id)) {
156154
check (fcx.ccx.item_types.contains_key(id));
157-
t = fcx.ccx.item_types.get(id);
158-
ty_params = some(fcx.ccx.item_ty_params.get(id));
155+
ret tup(some(fcx.ccx.item_ty_params.get(id)),
156+
fcx.ccx.item_types.get(id));
159157
}
160158
case (ast.def_native_fn(?id)) {
161159
check (fcx.ccx.item_types.contains_key(id));
162-
t = fcx.ccx.item_types.get(id);
163-
ty_params = some(fcx.ccx.item_ty_params.get(id));
160+
ret tup(some(fcx.ccx.item_ty_params.get(id)),
161+
fcx.ccx.item_types.get(id));
164162
}
165163
case (ast.def_const(?id)) {
166164
check (fcx.ccx.item_types.contains_key(id));
167-
t = fcx.ccx.item_types.get(id);
168-
ty_params = none[vec[ast.def_id]];
165+
ret tup(none[vec[ast.def_id]], fcx.ccx.item_types.get(id));
169166
}
170167
case (ast.def_variant(?tag_id, ?variant_id)) {
171168
check (fcx.ccx.item_types.contains_key(variant_id));
172-
t = fcx.ccx.item_types.get(variant_id);
173-
ty_params = some(fcx.ccx.item_ty_params.get(tag_id));
169+
ret tup(some(fcx.ccx.item_ty_params.get(tag_id)),
170+
fcx.ccx.item_types.get(variant_id));
174171
}
175172
case (ast.def_binding(?id)) {
176173
check (fcx.locals.contains_key(id));
177-
t = fcx.locals.get(id);
178-
ty_params = none[vec[ast.def_id]];
174+
ret tup(none[vec[ast.def_id]], fcx.locals.get(id));
179175
}
180176
case (ast.def_obj(?id)) {
181177
check (fcx.ccx.item_types.contains_key(id));
182-
t = fcx.ccx.item_types.get(id);
183-
ty_params = some(fcx.ccx.item_ty_params.get(id));
178+
ret tup(some(fcx.ccx.item_ty_params.get(id)),
179+
fcx.ccx.item_types.get(id));
184180
}
185181

186182
case (ast.def_mod(_)) {
187183
// Hopefully part of a path.
188-
t = plain_ty(ty.ty_nil); // TODO: something more poisonous?
189-
ty_params = none[vec[ast.def_id]];
184+
// TODO: return a type that's more poisonous, perhaps?
185+
ret tup(none[vec[ast.def_id]], plain_ty(ty.ty_nil));
190186
}
191187

192188
case (_) {
193189
// FIXME: handle other names.
194-
fcx.ccx.sess.unimpl("definition variant for: "
195-
+ _str.connect(pth.node.idents, "."));
190+
fcx.ccx.sess.unimpl("definition variant");
196191
fail;
197192
}
198193
}
194+
}
195+
196+
// Instantiates the given path, which must refer to an item with the given
197+
// type parameters and type.
198+
fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ty_params_opt_and_ty tpt,
199+
&span sp) -> ast.ann {
200+
auto ty_params = tpt._0;
201+
auto t = tpt._1;
199202

200203
auto ty_substs_opt;
201204
auto ty_substs_len = _vec.len[@ast.ty](pth.node.types);
@@ -1669,7 +1672,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
16691672
auto t = plain_ty(ty.ty_nil);
16701673
check (defopt != none[ast.def]);
16711674
auto defn = option.get[ast.def](defopt);
1672-
auto ann = instantiate_path(fcx, pth, defn, expr.span);
1675+
auto tpt = ty_params_and_ty_for_def(fcx, defn);
1676+
auto ann = instantiate_path(fcx, pth, tpt, expr.span);
16731677
ret @fold.respan[ast.expr_](expr.span,
16741678
ast.expr_path(pth, defopt, ann));
16751679
}

0 commit comments

Comments
 (0)