Skip to content

Commit be18d82

Browse files
cixtorgraydon
authored andcommitted
---
yaml --- r: 1284 b: refs/heads/master c: c6dec37 h: refs/heads/master v: v3
1 parent 2496e15 commit be18d82

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
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: 546d1440095771a58ce7c68ebec56cf612266b58
2+
refs/heads/master: c6dec379b0870ea1a56bfbe9126b5f9c751a17ea

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
446446
generic-fn-infer.rs \
447447
generic-drop-glue.rs \
448448
generic-tup.rs \
449+
generic-type.rs \
449450
hello.rs \
450451
int.rs \
451452
i32-sub.rs \

trunk/src/comp/middle/resolve.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@ fn fold_ty_path(&env e, &span sp, ast.path p, &option.t[def] d) -> @ast.ty {
476476
e.sess.unimpl("resolving path ty with >1 component");
477477
}
478478

479-
if (_vec.len[@ast.ty](p.node.types) > 0u) {
480-
e.sess.unimpl("resolving path ty with ty params");
481-
}
482-
483479
auto d_ = lookup_name(e, p.node.idents.(0));
484480

485481
alt (d_) {

trunk/src/comp/middle/typeck.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
8181
ret rec(mode=arg.mode, ty=ast_ty_to_ty(getter, arg.ty));
8282
}
8383

84+
fn replace_type_params(@ty.t t, ty_table param_map) -> @ty.t {
85+
state obj param_replacer(ty_table param_map) {
86+
fn fold_simple_ty(@ty.t t) -> @ty.t {
87+
alt (t.struct) {
88+
case (ty.ty_param(?param_def)) {
89+
ret param_map.get(param_def);
90+
}
91+
case (_) {
92+
ret t;
93+
}
94+
}
95+
}
96+
}
97+
auto replacer = param_replacer(param_map);
98+
ret ty.fold_ty(replacer, t);
99+
}
100+
84101
auto mut = ast.imm;
85102
auto sty;
86103
auto cname = none[str];
@@ -122,7 +139,20 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
122139
case (ast.def_ty(?id)) {
123140
// TODO: maybe record cname chains so we can do
124141
// "foo = int" like OCaml?
125-
sty = getter(id).ty.struct;
142+
auto ty_and_params = getter(id);
143+
auto params = ty_and_params.params;
144+
auto num_type_params = _vec.len[@ast.ty](path.node.types);
145+
check(num_type_params == _vec.len[ast.ty_param](params));
146+
147+
auto param_map = common.new_def_hash[@ty.t]();
148+
for each (uint i in _uint.range(0u, num_type_params)) {
149+
auto x = path.node.types.(i);
150+
auto y = params.(i);
151+
param_map.insert(y.id, ast_ty_to_ty(getter, x));
152+
}
153+
154+
sty = replace_type_params(ty_and_params.ty,
155+
param_map).struct;
126156
}
127157
case (ast.def_ty_arg(?id)) { sty = ty.ty_param(id); }
128158
case (_) { fail; }

0 commit comments

Comments
 (0)