chore: eliminate todo!s

This commit is contained in:
Shunsuke Shibayama 2023-08-24 23:54:31 +09:00
parent 936b6e2f95
commit 46c7982335
5 changed files with 46 additions and 22 deletions

View file

@ -1441,8 +1441,10 @@ impl Context {
Predicate::Const(name) => {
if let Some(value) = self.rec_get_const_obj(name) {
value.class()
} else if DEBUG_MODE {
todo!("get_pred_type({name})");
} else {
todo!("get_pred_type({name})")
Obj
}
}
}

View file

@ -134,7 +134,12 @@ impl Generalizer {
TyParam::unary(op, val)
}
other if other.has_no_unbound_var() => other,
other => todo!("{other:?}"),
other => {
if DEBUG_MODE {
todo!("{other:?}");
}
other
}
}
}

View file

@ -2,7 +2,7 @@
use std::option::Option; // conflicting to Type::Option
use std::path::{Path, PathBuf};
use erg_common::consts::{ERG_MODE, PYTHON_MODE};
use erg_common::consts::{DEBUG_MODE, ERG_MODE, PYTHON_MODE};
use erg_common::error::{ErrorCore, Location, SubMessage};
use erg_common::io::Input;
use erg_common::levenshtein;
@ -2318,16 +2318,16 @@ impl Context {
t: &Type,
) -> Option<impl Iterator<Item = &'a Context>> {
let (_, ctx) = self.get_nominal_type_ctx(t)?;
let sups = ctx
.super_classes
.iter()
.chain(ctx.super_traits.iter())
.map(|sup| {
self.get_nominal_type_ctx(sup)
.unwrap_or_else(|| todo!("compiler bug: {sup} not found"))
.1
});
Some(vec![ctx].into_iter().chain(sups))
let sups = ctx.super_classes.iter().chain(ctx.super_traits.iter());
let mut sup_ctxs = vec![];
for sup in sups {
if let Some((_, ctx)) = self.get_nominal_type_ctx(sup) {
sup_ctxs.push(ctx);
} else if DEBUG_MODE {
todo!("no ctx for {sup}");
}
}
Some(vec![ctx].into_iter().chain(sup_ctxs))
}
pub(crate) fn _get_super_traits(&self, typ: &Type) -> Option<impl Iterator<Item = Type>> {

View file

@ -2,6 +2,7 @@ use std::fmt;
use std::mem;
use std::option::Option; // conflicting to Type::Option
use erg_common::consts::DEBUG_MODE;
use erg_common::dict::Dict;
use erg_common::enum_unwrap;
#[allow(unused)]
@ -12,9 +13,7 @@ use erg_common::Str;
use erg_parser::ast::VarName;
use crate::ty::constructors::*;
use crate::ty::free::FreeTyParam;
use crate::ty::free::GENERIC_LEVEL;
use crate::ty::free::{Constraint, HasLevel};
use crate::ty::free::{Constraint, FreeTyParam, FreeTyVar, HasLevel, GENERIC_LEVEL};
use crate::ty::typaram::{TyParam, TyParamLambda};
use crate::ty::ConstSubr;
use crate::ty::ValueObj;
@ -203,8 +202,11 @@ impl TyVarCache {
// T<inst> is uninitialized
// T<inst>.link(T<tv>);
// T <: Eq(T <: Eq(T <: ...))
let Type::FreeVar(free_inst) = inst else {
todo!("{inst}")
let Ok(free_inst) = <&FreeTyVar>::try_from(inst) else {
if DEBUG_MODE {
todo!("{inst}");
}
return;
};
if free_inst.constraint_is_uninited() {
inst.destructive_link(tv);
@ -216,7 +218,12 @@ impl TyVarCache {
// tv: ?T(:> Nat)
// => ?T(:> Nat or Str)
let (old_sub, old_sup) = free_inst.get_subsup().unwrap();
let Type::FreeVar(tv) = tv else { todo!("{tv}") };
let Ok(tv) = <&FreeTyVar>::try_from(tv) else {
if DEBUG_MODE {
todo!("{tv}");
}
return;
};
let (new_sub, new_sup) = tv.get_subsup().unwrap();
let new_constraint = Constraint::new_sandwiched(
ctx.union(&old_sub, &new_sub),
@ -274,7 +281,10 @@ impl TyVarCache {
if let (Ok(inst), Ok(t)) = (<&Type>::try_from(inst), <&Type>::try_from(tp)) {
return self.update_tyvar(inst, t, ctx);
} else {
todo!("{inst}");
if DEBUG_MODE {
todo!("{inst}");
}
return;
}
};
if free_inst.constraint_is_uninited() {
@ -282,7 +292,10 @@ impl TyVarCache {
} else {
let old_type = free_inst.get_type().unwrap();
let Ok(tv) = <&FreeTyParam>::try_from(tp) else {
todo!("{tp}")
if DEBUG_MODE {
todo!("{tp}");
}
return;
};
let new_type = tv.get_type().unwrap();
let new_constraint = Constraint::new_type_of(ctx.intersection(&old_type, &new_type));

View file

@ -2,6 +2,7 @@
use std::mem;
use std::option::Option;
use erg_common::consts::DEBUG_MODE;
use erg_common::fresh::FRESH_GEN;
use erg_common::traits::Locational;
use erg_common::Str;
@ -509,7 +510,10 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
}
Ok(())
} else {
todo!()
if DEBUG_MODE {
todo!()
}
Ok(())
}
}
(l, r) => {