diff --git a/compiler/erg_compiler/context/inquire.rs b/compiler/erg_compiler/context/inquire.rs index de770c16..73279a66 100644 --- a/compiler/erg_compiler/context/inquire.rs +++ b/compiler/erg_compiler/context/inquire.rs @@ -1566,11 +1566,14 @@ impl Context { // -> K.variance() == vec![Contravariant, Covariant] // TODO: support keyword arguments pub(crate) fn type_params_variance(&self) -> Vec { + let match_tp_name = |tp: &TyParam, name: &VarName| -> bool { + tp.qual_name().as_ref() == Some(name.inspect()) + }; let in_inout = |t: &Type, name: &VarName| { (&t.qual_name()[..] == "Input" || &t.qual_name()[..] == "Output") && t.typarams() .first() - .map(|inner| inner.qual_name().as_ref() == Some(name.inspect())) + .map(|inner| match_tp_name(inner, name)) .unwrap_or(false) }; self.params @@ -1578,13 +1581,13 @@ impl Context { .map(|(opt_name, _)| { if let Some(name) = opt_name { // トレイトの変性を調べるときはsuper_classesも見る必要がある - if let Some(t) = self + if let Some(variance_trait) = self .super_traits .iter() .chain(self.super_classes.iter()) .find(|t| in_inout(t, name)) { - match &t.qual_name()[..] { + match &variance_trait.qual_name()[..] { "Output" => Variance::Covariant, "Input" => Variance::Contravariant, _ => unreachable!(), diff --git a/compiler/erg_compiler/context/tyvar.rs b/compiler/erg_compiler/context/tyvar.rs index 0968be45..b15da51e 100644 --- a/compiler/erg_compiler/context/tyvar.rs +++ b/compiler/erg_compiler/context/tyvar.rs @@ -18,7 +18,7 @@ use crate::ty::{HasType, Predicate, Type}; // use crate::context::eval::SubstContext; use crate::context::{Context, Variance}; use crate::error::{SingleTyCheckResult, TyCheckError, TyCheckErrors, TyCheckResult}; -use crate::{feature_error, hir, type_feature_error}; +use crate::{feature_error, hir, type_feature_error, unreachable_error}; use Predicate as Pred; use Type::*; @@ -1438,17 +1438,12 @@ impl Context { // * sub_unify({0}, ?T(:> {1}, <: Nat)): (?T(:> {0, 1}, <: Nat)) // * sub_unify(Bool, ?T(<: Bool or Y)): (?T == Bool) Constraint::Sandwiched { sub, sup } => { - /*if let Some(new_sub) = self.max(maybe_sub, sub) { - *constraint = - Constraint::new_sandwiched(new_sub.clone(), mem::take(sup), *cyclicity); - } else {*/ let new_sub = self.union(maybe_sub, sub); if sup.contains_union(&new_sub) { rfv.link(&new_sub); // Bool <: ?T <: Bool or Y ==> ?T == Bool } else { *constraint = Constraint::new_sandwiched(new_sub, mem::take(sup)); } - // } } // sub_unify(Nat, ?T(: Type)): (/* ?T(:> Nat) */) Constraint::TypeOf(ty) => { @@ -1705,7 +1700,8 @@ impl Context { self.sub_unify_pred(sub_first, sup_first, loc)?; return Ok(()); } - todo!("{sub}, {sup}") + log!(err "unification error: {sub} <: {sup}"); + unreachable_error!(TyCheckErrors, TyCheckError, self) } // {I: Int | I >= 1} <: Nat == {I: Int | I >= 0} (Type::Refinement(_), sup) => { diff --git a/compiler/erg_compiler/ty/typaram.rs b/compiler/erg_compiler/ty/typaram.rs index 6bf3ddf1..42594cb3 100644 --- a/compiler/erg_compiler/ty/typaram.rs +++ b/compiler/erg_compiler/ty/typaram.rs @@ -310,10 +310,10 @@ impl LimitedDisplay for TyParam { impl CanbeFree for TyParam { fn unbound_name(&self) -> Option { - if let TyParam::FreeVar(fv) = self { - fv.unbound_name() - } else { - None + match self { + TyParam::FreeVar(fv) => fv.unbound_name(), + TyParam::Type(t) => t.unbound_name(), + _ => None, } }