diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-03 16:37:41 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-01-03 16:37:41 +0100 |
| commit | 4e88d5ae92af1ebfb1d23e027db7133c669cca69 (patch) | |
| tree | e67b272d285756354af5e49ea65c0a0725073d8e | |
| parent | 5ea3c96938e6defa894c4ae646a75ba00c4dce22 (diff) | |
| download | rust-4e88d5ae92af1ebfb1d23e027db7133c669cca69.tar.gz rust-4e88d5ae92af1ebfb1d23e027db7133c669cca69.zip | |
Make resolution of dictionaries on bounded params work
Issue #1227
| -rw-r--r-- | src/comp/middle/trans_impl.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 13 | ||||
| -rw-r--r-- | src/test/run-pass/iface-to-str.rs | 10 |
3 files changed, 19 insertions, 8 deletions
diff --git a/src/comp/middle/trans_impl.rs b/src/comp/middle/trans_impl.rs index aab8aaf10fa..7bcd2f6d880 100644 --- a/src/comp/middle/trans_impl.rs +++ b/src/comp/middle/trans_impl.rs @@ -147,6 +147,8 @@ fn get_dict(bcx: @block_ctxt, origin: typeck::dict_origin) -> result { } rslt(bcx, PointerCast(bcx, dict, T_ptr(T_dict()))) } - typeck::dict_param(_param) { fail "FIXME[impl]"; } + typeck::dict_param(n_param, n_bound) { + rslt(bcx, option::get(bcx.fcx.lltyparams[n_param].dicts)[n_bound]) + } } } \ No newline at end of file diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 662516141dc..f5b6f0f736a 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1515,10 +1515,10 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes, } _ {} } + bound_n += 1u; } _ {} } - bound_n += 1u; } ret none; } @@ -2868,7 +2868,8 @@ fn check_for_main_fn(tcx: ty::ctxt, crate: @ast::crate) { type dict_res = @[dict_origin]; tag dict_origin { dict_static(ast::def_id, [ty::t], dict_res); - dict_param(uint); + // Param number, bound number + dict_param(uint, uint); } type dict_map = hashmap<ast::node_id, dict_res>; @@ -2882,7 +2883,7 @@ fn resolve_dicts(tcx: ty::ctxt, impl_map: resolve::impl_map, dict_map: dict_map}; let cx = {tcx: tcx, impl_map: impl_map, method_map: method_map, dict_map: new_int_hash()}; - + fn has_iface_bounds(tps: [ty::param_bounds]) -> bool { vec::any(tps, {|bs| vec::any(*bs, {|b| @@ -2947,21 +2948,23 @@ fn resolve_dicts(tcx: ty::ctxt, impl_map: resolve::impl_map, } fn lookup_dict(tcx: ty::ctxt, isc: resolve::iscopes, sp: span, - ty: ty::t, iface_ty: ty::t) -> dict_origin { + ty: ty::t, iface_ty: ty::t) -> dict_origin { let iface_id = alt ty::struct(tcx, iface_ty) { ty::ty_iface(did, _) { did } _ { tcx.sess.abort_if_errors(); fail; } }; alt ty::struct(tcx, ty) { ty::ty_param(n, did) { + let n_bound = 0u; for bound in *tcx.ty_param_bounds.get(did.node) { alt bound { ty::bound_iface(ity) { alt ty::struct(tcx, ity) { ty::ty_iface(idid, _) { - if did == idid { ret dict_param(n); } + if iface_id == idid { ret dict_param(n, n_bound); } } } + n_bound += 1u; } _ {} } diff --git a/src/test/run-pass/iface-to-str.rs b/src/test/run-pass/iface-to-str.rs index 406dae0ba38..cf30cefbd33 100644 --- a/src/test/run-pass/iface-to-str.rs +++ b/src/test/run-pass/iface-to-str.rs @@ -13,10 +13,16 @@ impl <T: to_str> of to_str for [T] { } fn main() { + assert 1.to_str() == "1"; + assert [2, 3, 4].to_str() == "[2, 3, 4]"; + fn indirect<T: to_str>(x: T) -> str { x.to_str() + "!" } - assert 1.to_str() == "1"; - assert [2, 3, 4].to_str() == "[2, 3, 4]"; assert indirect([10, 20]) == "[10, 20]!"; + + fn indirect2<T: to_str>(x: T) -> str { + indirect(x) + } + assert indirect2([1]) == "[1]!"; } |
