diff --git a/crates/erg_compiler/context/compare.rs b/crates/erg_compiler/context/compare.rs index 0614e3b6..7b4cf139 100644 --- a/crates/erg_compiler/context/compare.rs +++ b/crates/erg_compiler/context/compare.rs @@ -166,9 +166,9 @@ impl Context { return (Absolutely, true); } match (lhs, rhs) { - (Obj, _) | (_, Never | Failure) => (Absolutely, true), + (Obj | Failure, _) | (_, Never | Failure) => (Absolutely, true), (_, Obj) if lhs.is_mono_value_class() => (Absolutely, false), - (Never | Failure, _) if rhs.is_mono_value_class() => (Absolutely, false), + (Never, _) if rhs.is_mono_value_class() => (Absolutely, false), (Complex | Float | Ratio | Int | Nat | Bool, Bool) | (Complex | Float | Ratio | Int | Nat, Nat) | (Complex | Float | Ratio | Int, Int) diff --git a/crates/erg_compiler/context/generalize.rs b/crates/erg_compiler/context/generalize.rs index d80388c8..07929983 100644 --- a/crates/erg_compiler/context/generalize.rs +++ b/crates/erg_compiler/context/generalize.rs @@ -683,9 +683,6 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> { args: new_args, }) } - TyParam::Failure if self.level == 0 => Err(TyCheckErrors::from( - TyCheckError::dummy_infer_error(self.ctx.cfg.input.clone(), fn_name!(), line!()), - )), TyParam::Mono(_) | TyParam::Failure => Ok(tp), } } diff --git a/crates/erg_compiler/context/instantiate_spec.rs b/crates/erg_compiler/context/instantiate_spec.rs index 30f8b6f0..c96f6b8a 100644 --- a/crates/erg_compiler/context/instantiate_spec.rs +++ b/crates/erg_compiler/context/instantiate_spec.rs @@ -594,14 +594,16 @@ impl Context { .get_singular_ctxs(&attr.obj.clone().downgrade(), self) .map_err(|errs| (Type::Failure, errs.into()))?; for ctx in ctxs { - if let Ok(typ) = ctx.instantiate_local_poly_t( + match ctx.instantiate_local_poly_t( &attr.name, &poly.args, opt_decl_t, tmp_tv_cache, not_found_is_qvar, ) { - return Ok(typ); + Ok(typ) => return Ok(typ), + Err((Type::Failure, _)) => {} + Err((typ, es)) => return Err((typ, es)), } } Err(( diff --git a/crates/erg_compiler/ty/mod.rs b/crates/erg_compiler/ty/mod.rs index 9bad94dd..e210eece 100644 --- a/crates/erg_compiler/ty/mod.rs +++ b/crates/erg_compiler/ty/mod.rs @@ -1391,7 +1391,8 @@ pub enum Type { }, FreeVar(FreeTyVar), // a reference to the type of other expression, see docs/compiler/inference.md #[default] - Failure, // indicates a failure of type inference and behaves as `Never`. + /// for all T, `T <: Failure and T :> Failure` + Failure, // indicates a failure of type inference and behaves as `Any`. /// used to represent `TyParam` is not initialized (see `erg_compiler::context::instantiate_tp`) Uninited, }