@@ -25,6 +25,7 @@ tag method_origin {
25
25
method_static( ast:: def_id) ;
26
26
// iface id, method num, param num, bound num
27
27
method_param ( ast:: def_id, uint, uint, uint) ;
28
+ method_iface;
28
29
}
29
30
type method_map = hashmap < ast:: node_id , method_origin > ;
30
31
@@ -1572,6 +1573,16 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
1572
1573
}
1573
1574
ret none;
1574
1575
}
1576
+ ty:: ty_iface ( did, tps) {
1577
+ for m in * ty:: iface_methods ( tcx, did) {
1578
+ if m. ident == name {
1579
+ ret some ( { method_ty: ty:: mk_fn ( tcx, m. fty ) ,
1580
+ n_tps: vec:: len ( * m. tps ) ,
1581
+ substs: tps,
1582
+ origin: method_iface} ) ;
1583
+ }
1584
+ }
1585
+ }
1575
1586
_ { }
1576
1587
}
1577
1588
@@ -2192,13 +2203,18 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
2192
2203
ty_to_str ( tcx, t_1) ) ;
2193
2204
}
2194
2205
2195
- // FIXME there are more forms of cast to support, eventually.
2196
- if !( type_is_scalar ( fcx, expr. span , t_e)
2197
- && type_is_scalar ( fcx, expr. span , t_1) ) {
2198
- tcx. sess . span_err ( expr. span ,
2199
- "non-scalar cast: " +
2206
+ alt ty:: struct ( tcx, t_1) {
2207
+ // This will be looked up later on
2208
+ ty:: ty_iface ( _, _) { }
2209
+ _ {
2210
+ // FIXME there are more forms of cast to support, eventually.
2211
+ if ! ( type_is_scalar( fcx, expr. span, t_e)
2212
+ && type_is_scalar( fcx, expr. span, t_1) ) {
2213
+ tcx. sess . span_err ( expr. span , "non-scalar cast: " +
2200
2214
ty_to_str ( tcx, t_e) + " as " +
2201
2215
ty_to_str ( tcx, t_1) ) ;
2216
+ }
2217
+ }
2202
2218
}
2203
2219
write:: ty_only_fixup( fcx, id, t_1) ;
2204
2220
}
@@ -3019,6 +3035,18 @@ mod dict {
3019
3035
_ { }
3020
3036
}
3021
3037
}
3038
+ ast:: expr_cast ( src, _) {
3039
+ let target_ty = expr_ty ( cx. tcx , ex) ;
3040
+ alt ty:: struct ( cx. tcx , target_ty) {
3041
+ ty:: ty_iface ( _, _) {
3042
+ let impls = cx. impl_map . get ( ex. id ) ;
3043
+ let dict = lookup_dict ( fcx, impls, ex. span ,
3044
+ expr_ty ( cx. tcx , src) , target_ty) ;
3045
+ cx. dict_map . insert ( ex. id , @[ dict] ) ;
3046
+ }
3047
+ _ { }
3048
+ }
3049
+ }
3022
3050
ast:: expr_fn ( ast:: proto_block. , _, _, _) { }
3023
3051
ast:: expr_fn ( _, _, _, _) { ret; }
3024
3052
_ { }
0 commit comments