chore: Failure == Any

This commit is contained in:
Shunsuke Shibayama 2024-10-04 14:38:34 +09:00
parent 44192b2382
commit a9cd32d553
4 changed files with 8 additions and 8 deletions

View file

@ -166,9 +166,9 @@ impl Context {
return (Absolutely, true); return (Absolutely, true);
} }
match (lhs, rhs) { match (lhs, rhs) {
(Obj, _) | (_, Never | Failure) => (Absolutely, true), (Obj | Failure, _) | (_, Never | Failure) => (Absolutely, true),
(_, Obj) if lhs.is_mono_value_class() => (Absolutely, false), (_, 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 | Bool, Bool)
| (Complex | Float | Ratio | Int | Nat, Nat) | (Complex | Float | Ratio | Int | Nat, Nat)
| (Complex | Float | Ratio | Int, Int) | (Complex | Float | Ratio | Int, Int)

View file

@ -683,9 +683,6 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> {
args: new_args, 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), TyParam::Mono(_) | TyParam::Failure => Ok(tp),
} }
} }

View file

@ -594,14 +594,16 @@ impl Context {
.get_singular_ctxs(&attr.obj.clone().downgrade(), self) .get_singular_ctxs(&attr.obj.clone().downgrade(), self)
.map_err(|errs| (Type::Failure, errs.into()))?; .map_err(|errs| (Type::Failure, errs.into()))?;
for ctx in ctxs { for ctx in ctxs {
if let Ok(typ) = ctx.instantiate_local_poly_t( match ctx.instantiate_local_poly_t(
&attr.name, &attr.name,
&poly.args, &poly.args,
opt_decl_t, opt_decl_t,
tmp_tv_cache, tmp_tv_cache,
not_found_is_qvar, not_found_is_qvar,
) { ) {
return Ok(typ); Ok(typ) => return Ok(typ),
Err((Type::Failure, _)) => {}
Err((typ, es)) => return Err((typ, es)),
} }
} }
Err(( Err((

View file

@ -1391,7 +1391,8 @@ pub enum Type {
}, },
FreeVar(FreeTyVar), // a reference to the type of other expression, see docs/compiler/inference.md FreeVar(FreeTyVar), // a reference to the type of other expression, see docs/compiler/inference.md
#[default] #[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`) /// used to represent `TyParam` is not initialized (see `erg_compiler::context::instantiate_tp`)
Uninited, Uninited,
} }