Change the level of forcing in structurally_resolved_type().
A cleaner way to handle suffix inference for unary minus exprs.
This commit is contained in:
parent
317864672d
commit
abfa8164cd
2 changed files with 10 additions and 17 deletions
|
@ -74,7 +74,7 @@ import rscope::{anon_rscope, binding_rscope, empty_rscope, in_anon_rscope};
|
|||
import rscope::{in_binding_rscope, region_scope, type_rscope};
|
||||
import syntax::ast::ty_i;
|
||||
import typeck::infer::{unify_methods}; // infcx.set()
|
||||
import typeck::infer::{force_level, force_none, force_non_region_vars_only,
|
||||
import typeck::infer::{force_level, force_none, force_ty_vars_only,
|
||||
force_all};
|
||||
|
||||
type fn_ctxt =
|
||||
|
@ -1174,14 +1174,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
|||
}
|
||||
}
|
||||
ast::neg {
|
||||
// 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);
|
||||
}
|
||||
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,
|
||||
|
@ -2116,7 +2109,7 @@ fn instantiate_path(fcx: @fn_ctxt,
|
|||
// resolution is possible, then an error is reported.
|
||||
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
|
||||
alt infer::resolve_shallow(fcx.infcx, tp,
|
||||
force_non_region_vars_only) {
|
||||
force_ty_vars_only) {
|
||||
result::ok(t_s) if !ty::type_is_var(t_s) { ret t_s; }
|
||||
_ {
|
||||
fcx.ccx.tcx.sess.span_fatal
|
||||
|
|
|
@ -197,7 +197,7 @@ export fixup_err, fixup_err_to_str;
|
|||
export assignment;
|
||||
export root, to_str;
|
||||
export int_ty_set_all;
|
||||
export force_level, force_none, force_non_region_vars_only, force_all;
|
||||
export force_level, force_none, force_ty_vars_only, force_all;
|
||||
|
||||
// Bitvector to represent sets of integral types
|
||||
enum int_ty_set = uint;
|
||||
|
@ -1093,9 +1093,9 @@ enum force_level {
|
|||
// Any unconstrained variables are OK.
|
||||
force_none,
|
||||
|
||||
// Unconstrained region vars are OK; unconstrained ty vars and
|
||||
// integral ty vars result in an error.
|
||||
force_non_region_vars_only,
|
||||
// Unconstrained region vars and integral ty vars are OK;
|
||||
// unconstrained general-purpose ty vars result in an error.
|
||||
force_ty_vars_only,
|
||||
|
||||
// Any unconstrained variables result in an error.
|
||||
force_all,
|
||||
|
@ -1237,7 +1237,7 @@ impl methods for resolve_state {
|
|||
{ ub:_, lb:some(t) } { self.resolve1(t) }
|
||||
{ ub:none, lb:none } {
|
||||
alt self.force_vars {
|
||||
force_non_region_vars_only | force_all {
|
||||
force_ty_vars_only | force_all {
|
||||
self.err = some(unresolved_ty(vid));
|
||||
}
|
||||
force_none { /* ok */ }
|
||||
|
@ -1260,7 +1260,7 @@ impl methods for resolve_state {
|
|||
some(t) { t }
|
||||
none {
|
||||
alt self.force_vars {
|
||||
force_non_region_vars_only | force_all {
|
||||
force_all {
|
||||
// As a last resort, default to int.
|
||||
let ty = ty::mk_int(self.infcx.tcx);
|
||||
self.infcx.set(
|
||||
|
@ -1270,7 +1270,7 @@ impl methods for resolve_state {
|
|||
nde.rank));
|
||||
ty
|
||||
}
|
||||
force_none {
|
||||
force_none | force_ty_vars_only {
|
||||
ty::mk_var_integral(self.infcx.tcx, vid)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue