Use the right types for methods in trans_impl
This prevents misalignment between function and argument types in corner cases.
This commit is contained in:
parent
71c1c15805
commit
3971b520bc
@ -115,8 +115,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, is_method: bool, inputs: [ty::arg],
|
||||
|
||||
// Given a function type and a count of ty params, construct an llvm type
|
||||
fn type_of_fn_from_ty(cx: @crate_ctxt, sp: span, fty: ty::t,
|
||||
param_bounds: [ty::param_bounds])
|
||||
: returns_non_ty_var(cx, fty) -> TypeRef {
|
||||
param_bounds: [ty::param_bounds]) -> TypeRef {
|
||||
// FIXME: Check should be unnecessary, b/c it's implied
|
||||
// by returns_non_ty_var(t). Make that a postcondition
|
||||
// (see Issue #586)
|
||||
@ -173,8 +172,6 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
|
||||
T_struct(tys)
|
||||
}
|
||||
ty::ty_fn(_) {
|
||||
// FIXME: could be a constraint on ty_fn
|
||||
check returns_non_ty_var(cx, t);
|
||||
T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, []))
|
||||
}
|
||||
ty::ty_native_fn(args, out) {
|
||||
@ -242,7 +239,6 @@ fn type_of_ty_param_bounds_and_ty(lcx: @local_ctxt, sp: span,
|
||||
let t = tpt.ty;
|
||||
alt ty::struct(cx.tcx, t) {
|
||||
ty::ty_fn(_) | ty::ty_native_fn(_, _) {
|
||||
check returns_non_ty_var(cx, t);
|
||||
ret type_of_fn_from_ty(cx, sp, t, *tpt.bounds);
|
||||
}
|
||||
_ {
|
||||
@ -5300,7 +5296,6 @@ fn collect_native_item(ccx: @crate_ctxt,
|
||||
ast::native_abi_rust_intrinsic. {
|
||||
// For intrinsics: link the function directly to the intrinsic
|
||||
// function itself.
|
||||
check returns_non_ty_var(ccx, node_type);
|
||||
let fn_type = type_of_fn_from_ty(
|
||||
ccx, sp, node_type,
|
||||
vec::map(tps, {|p| param_bounds(ccx, p)}));
|
||||
|
@ -405,7 +405,6 @@ fn trans_expr_fn(bcx: @block_ctxt,
|
||||
if dest == ignore { ret bcx; }
|
||||
let ccx = bcx_ccx(bcx), bcx = bcx;
|
||||
let fty = node_id_type(ccx, id);
|
||||
check returns_non_ty_var(ccx, fty);
|
||||
let llfnty = type_of_fn_from_ty(ccx, sp, fty, []);
|
||||
let sub_cx = extend_path(bcx.fcx.lcx, ccx.names.next("anon"));
|
||||
let s = mangle_internal_name_by_path(ccx, sub_cx.path);
|
||||
@ -779,7 +778,6 @@ fn trans_bind_thunk(cx: @local_ctxt,
|
||||
// needs to take.
|
||||
let ccx = bcx_ccx(bcx);
|
||||
|
||||
check returns_non_ty_var(ccx, outgoing_fty);
|
||||
let lltargetty =
|
||||
type_of_fn_from_ty(ccx, sp, outgoing_fty, param_bounds);
|
||||
lltargetfn = PointerCast(bcx, lltargetfn, T_ptr(lltargetty));
|
||||
|
@ -44,9 +44,9 @@ fn trans_dict_callee(bcx: @block_ctxt, e: @ast::expr, base: @ast::expr,
|
||||
let {bcx, val} = trans_self_arg(bcx, base);
|
||||
let dict = option::get(bcx.fcx.lltyparams[n_param].dicts)[n_bound];
|
||||
let method = ty::iface_methods(tcx, iface_id)[n_method];
|
||||
let bare_fn_ty = type_of_fn(bcx_ccx(bcx), ast_util::dummy_sp(),
|
||||
false, method.fty.inputs, method.fty.output,
|
||||
*method.tps);
|
||||
let fty = ty::expr_ty(tcx, e);
|
||||
let bare_fn_ty = type_of_fn_from_ty(bcx_ccx(bcx), ast_util::dummy_sp(),
|
||||
fty, *method.tps);
|
||||
let {inputs: bare_inputs, output} = llfn_arg_tys(bare_fn_ty);
|
||||
let fn_ty = T_fn([val_ty(dict)] + bare_inputs, output);
|
||||
let vtable = PointerCast(bcx, Load(bcx, GEPi(bcx, dict, [0, 0])),
|
||||
@ -63,7 +63,7 @@ fn trans_dict_callee(bcx: @block_ctxt, e: @ast::expr, base: @ast::expr,
|
||||
tydescs += [td.val];
|
||||
bcx = td.bcx;
|
||||
}
|
||||
generic = some({item_type: ty::mk_fn(tcx, method.fty),
|
||||
generic = some({item_type: fty,
|
||||
static_tis: tis,
|
||||
tydescs: tydescs,
|
||||
param_bounds: method.tps,
|
||||
|
Loading…
x
Reference in New Issue
Block a user