Skip to content

Commit 4e88d5a

Browse files
committed
Make resolution of dictionaries on bounded params work
Issue #1227
1 parent 5ea3c96 commit 4e88d5a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/comp/middle/trans_impl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ fn get_dict(bcx: @block_ctxt, origin: typeck::dict_origin) -> result {
147147
}
148148
rslt(bcx, PointerCast(bcx, dict, T_ptr(T_dict())))
149149
}
150-
typeck::dict_param(_param) { fail "FIXME[impl]"; }
150+
typeck::dict_param(n_param, n_bound) {
151+
rslt(bcx, option::get(bcx.fcx.lltyparams[n_param].dicts)[n_bound])
152+
}
151153
}
152154
}

src/comp/middle/typeck.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1515,10 +1515,10 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15151515
}
15161516
_ {}
15171517
}
1518+
bound_n += 1u;
15181519
}
15191520
_ {}
15201521
}
1521-
bound_n += 1u;
15221522
}
15231523
ret none;
15241524
}
@@ -2868,7 +2868,8 @@ fn check_for_main_fn(tcx: ty::ctxt, crate: @ast::crate) {
28682868
type dict_res = @[dict_origin];
28692869
tag dict_origin {
28702870
dict_static(ast::def_id, [ty::t], dict_res);
2871-
dict_param(uint);
2871+
// Param number, bound number
2872+
dict_param(uint, uint);
28722873
}
28732874
type dict_map = hashmap<ast::node_id, dict_res>;
28742875

@@ -2882,7 +2883,7 @@ fn resolve_dicts(tcx: ty::ctxt, impl_map: resolve::impl_map,
28822883
dict_map: dict_map};
28832884
let cx = {tcx: tcx, impl_map: impl_map,
28842885
method_map: method_map, dict_map: new_int_hash()};
2885-
2886+
28862887
fn has_iface_bounds(tps: [ty::param_bounds]) -> bool {
28872888
vec::any(tps, {|bs|
28882889
vec::any(*bs, {|b|
@@ -2947,21 +2948,23 @@ fn resolve_dicts(tcx: ty::ctxt, impl_map: resolve::impl_map,
29472948
}
29482949

29492950
fn lookup_dict(tcx: ty::ctxt, isc: resolve::iscopes, sp: span,
2950-
ty: ty::t, iface_ty: ty::t) -> dict_origin {
2951+
ty: ty::t, iface_ty: ty::t) -> dict_origin {
29512952
let iface_id = alt ty::struct(tcx, iface_ty) {
29522953
ty::ty_iface(did, _) { did }
29532954
_ { tcx.sess.abort_if_errors(); fail; }
29542955
};
29552956
alt ty::struct(tcx, ty) {
29562957
ty::ty_param(n, did) {
2958+
let n_bound = 0u;
29572959
for bound in *tcx.ty_param_bounds.get(did.node) {
29582960
alt bound {
29592961
ty::bound_iface(ity) {
29602962
alt ty::struct(tcx, ity) {
29612963
ty::ty_iface(idid, _) {
2962-
if did == idid { ret dict_param(n); }
2964+
if iface_id == idid { ret dict_param(n, n_bound); }
29632965
}
29642966
}
2967+
n_bound += 1u;
29652968
}
29662969
_ {}
29672970
}

src/test/run-pass/iface-to-str.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ impl <T: to_str> of to_str for [T] {
1313
}
1414

1515
fn main() {
16+
assert 1.to_str() == "1";
17+
assert [2, 3, 4].to_str() == "[2, 3, 4]";
18+
1619
fn indirect<T: to_str>(x: T) -> str {
1720
x.to_str() + "!"
1821
}
19-
assert 1.to_str() == "1";
20-
assert [2, 3, 4].to_str() == "[2, 3, 4]";
2122
assert indirect([10, 20]) == "[10, 20]!";
23+
24+
fn indirect2<T: to_str>(x: T) -> str {
25+
indirect(x)
26+
}
27+
assert indirect2([1]) == "[1]!";
2228
}

0 commit comments

Comments
 (0)