Don't force resolution of integral type vars in unary minus exprs
These were getting resolved too early, when they were still unconstrained by the rest of the typing context. Waiting a bit longer to resolve them gives the rest of the typing context a chance to come into play, so that they don't default to `int`.
This commit is contained in:
parent
64912c9a56
commit
60a658250e
@ -1198,7 +1198,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
}
|
||||
}
|
||||
ast::neg {
|
||||
oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t);
|
||||
// If the operand's type is an integral type variable, we
|
||||
// don't want to resolve it yet, because the rest of the
|
||||
// typing context might not have had the opportunity to
|
||||
// constrain it yet.
|
||||
if !(ty::type_is_var_integral(oprnd_t)) {
|
||||
oprnd_t = structurally_resolved_type(fcx, oprnd.span,
|
||||
oprnd_t);
|
||||
}
|
||||
if !(ty::type_is_integral(oprnd_t) ||
|
||||
ty::type_is_fp(oprnd_t)) {
|
||||
oprnd_t = check_user_unop(fcx, "-", "unary-", expr,
|
||||
|
@ -16,22 +16,22 @@ fn main() {
|
||||
|
||||
let _i: i8 = -128;
|
||||
let j = -128;
|
||||
// id_i8(j);
|
||||
id_i8(j);
|
||||
id_i8(-128);
|
||||
|
||||
let _i: i16 = -32_768;
|
||||
let j = -32_768;
|
||||
// id_i16(j);
|
||||
id_i16(j);
|
||||
id_i16(-32_768);
|
||||
|
||||
let _i: i32 = -2_147_483_648;
|
||||
let j = -2_147_483_648;
|
||||
// id_i32(j);
|
||||
id_i32(j);
|
||||
id_i32(-2_147_483_648);
|
||||
|
||||
let _i: i64 = -9_223_372_036_854_775_808;
|
||||
let j = -9_223_372_036_854_775_808;
|
||||
// id_i64(j);
|
||||
id_i64(j);
|
||||
id_i64(-9_223_372_036_854_775_808);
|
||||
|
||||
let _i: uint = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user