Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
generic-fn-infer.rs \
generic-drop-glue.rs \
generic-tup.rs \
generic-type.rs \
hello.rs \
int.rs \
i32-sub.rs \
Expand Down
4 changes: 0 additions & 4 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,6 @@ fn fold_ty_path(&env e, &span sp, ast.path p, &option.t[def] d) -> @ast.ty {
e.sess.unimpl("resolving path ty with >1 component");
}

if (_vec.len[@ast.ty](p.node.types) > 0u) {
e.sess.unimpl("resolving path ty with ty params");
}

auto d_ = lookup_name(e, p.node.idents.(0));

alt (d_) {
Expand Down
32 changes: 31 additions & 1 deletion src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
ret rec(mode=arg.mode, ty=ast_ty_to_ty(getter, arg.ty));
}

fn replace_type_params(@ty.t t, ty_table param_map) -> @ty.t {
state obj param_replacer(ty_table param_map) {
fn fold_simple_ty(@ty.t t) -> @ty.t {
alt (t.struct) {
case (ty.ty_param(?param_def)) {
ret param_map.get(param_def);
}
case (_) {
ret t;
}
}
}
}
auto replacer = param_replacer(param_map);
ret ty.fold_ty(replacer, t);
}

auto mut = ast.imm;
auto sty;
auto cname = none[str];
Expand Down Expand Up @@ -122,7 +139,20 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
case (ast.def_ty(?id)) {
// TODO: maybe record cname chains so we can do
// "foo = int" like OCaml?
sty = getter(id).ty.struct;
auto ty_and_params = getter(id);
auto params = ty_and_params.params;
auto num_type_params = _vec.len[@ast.ty](path.node.types);
check(num_type_params == _vec.len[ast.ty_param](params));

auto param_map = common.new_def_hash[@ty.t]();
for each (uint i in _uint.range(0u, num_type_params)) {
auto x = path.node.types.(i);
auto y = params.(i);
param_map.insert(y.id, ast_ty_to_ty(getter, x));
}

sty = replace_type_params(ty_and_params.ty,
param_map).struct;
}
case (ast.def_ty_arg(?id)) { sty = ty.ty_param(id); }
case (_) { fail; }
Expand Down