bug fixes

This commit is contained in:
Shunsuke Shibayama 2022-10-07 20:15:53 +09:00
parent 9fc1376a9f
commit 4968076541
6 changed files with 13 additions and 7 deletions

View file

@ -217,7 +217,7 @@ fn is_fake_method(class: &str, name: &str) -> bool {
fn convert_to_python_attr(class: &str, uniq_obj_name: Option<&str>, name: Str) -> Str { fn convert_to_python_attr(class: &str, uniq_obj_name: Option<&str>, name: Str) -> Str {
match (class, uniq_obj_name, &name[..]) { match (class, uniq_obj_name, &name[..]) {
("Array!", _, "push!") => Str::ever("append"), ("Array!", _, "push!") => Str::ever("append"),
("Set!", _, "add") => Str::ever("add"), ("Set!", _, "add!") => Str::ever("add"),
("Complex" | "Float" | "Ratio" | "Int" | "Nat" | "Bool", _, "Real") => Str::ever("real"), ("Complex" | "Float" | "Ratio" | "Int" | "Nat" | "Bool", _, "Real") => Str::ever("real"),
("Complex" | "Float" | "Ratio" | "Int" | "Nat" | "Bool", _, "Imag") => Str::ever("imag"), ("Complex" | "Float" | "Ratio" | "Int" | "Nat" | "Bool", _, "Imag") => Str::ever("imag"),
("File!", _, "read!") => Str::ever("read"), ("File!", _, "read!") => Str::ever("read"),

View file

@ -870,8 +870,9 @@ impl Context {
/// returns union of two types (A or B) /// returns union of two types (A or B)
pub(crate) fn union(&self, lhs: &Type, rhs: &Type) -> Type { pub(crate) fn union(&self, lhs: &Type, rhs: &Type) -> Type {
// ?T or ?U will not be unified // `?T or ?U` will not be unified
if lhs.has_no_unbound_var() && rhs.has_no_unbound_var() { // `Set!(?T, 3) or Set(?T, 3)` wii be unified to Set(?T, 3)
if !lhs.is_unbound_var() && !rhs.is_unbound_var() {
match (self.supertype_of(lhs, rhs), self.subtype_of(lhs, rhs)) { match (self.supertype_of(lhs, rhs), self.subtype_of(lhs, rhs)) {
(true, true) => return lhs.clone(), // lhs = rhs (true, true) => return lhs.clone(), // lhs = rhs
(true, false) => return lhs.clone(), // lhs :> rhs (true, false) => return lhs.clone(), // lhs :> rhs

View file

@ -1071,6 +1071,8 @@ impl Context {
true true
} }
} }
(TyParam::Erased(t), _) => t.as_ref() == &self.get_tp_t(rhs).unwrap(),
(_, TyParam::Erased(t)) => t.as_ref() == &self.get_tp_t(lhs).unwrap(),
(TyParam::MonoQVar(_), _) | (_, TyParam::MonoQVar(_)) => false, (TyParam::MonoQVar(_), _) | (_, TyParam::MonoQVar(_)) => false,
(l, r) => todo!("l: {l}, r: {r}"), (l, r) => todo!("l: {l}, r: {r}"),
} }

View file

@ -882,7 +882,7 @@ impl Context {
set_.register_marker_trait(builtin_poly("Seq", vec![ty_tp(mono_q("T"))])); set_.register_marker_trait(builtin_poly("Seq", vec![ty_tp(mono_q("T"))]));
let mut set_show = Self::builtin_methods("Show", 1); let mut set_show = Self::builtin_methods("Show", 1);
set_show.register_builtin_impl("to_str", fn0_met(set_t.clone(), Str), Immutable, Public); set_show.register_builtin_impl("to_str", fn0_met(set_t.clone(), Str), Immutable, Public);
set_.register_trait(set_t, builtin_mono("Show"), set_show); set_.register_trait(set_t.clone(), builtin_mono("Show"), set_show);
/* Bytes */ /* Bytes */
let mut bytes = Self::builtin_mono_class("Bytes", 2); let mut bytes = Self::builtin_mono_class("Bytes", 2);
bytes.register_superclass(Obj, &obj); bytes.register_superclass(Obj, &obj);
@ -1553,7 +1553,6 @@ impl Context {
array_mut_mutable, array_mut_mutable,
); );
/* Set_mut */ /* Set_mut */
let set_t = builtin_poly("Set", vec![ty_tp(mono_q("T")), mono_q_tp("N")]);
let set_mut_t = builtin_poly("Set!", vec![ty_tp(mono_q("T")), mono_q_tp("N")]); let set_mut_t = builtin_poly("Set!", vec![ty_tp(mono_q("T")), mono_q_tp("N")]);
let mut set_mut_ = Self::builtin_poly_class( let mut set_mut_ = Self::builtin_poly_class(
"Set!", "Set!",
@ -1567,7 +1566,7 @@ impl Context {
set_mut_t.clone(), set_mut_t.clone(),
Some(builtin_poly( Some(builtin_poly(
"Set!", "Set!",
vec![ty_tp(mono_q("T")), TyParam::erased(Nat)], vec![ty_tp(mono_q("T")), TyParam::erased(builtin_mono("Nat!"))],
)), )),
), ),
vec![kw("elem", mono_q("T"))], vec![kw("elem", mono_q("T"))],

View file

@ -946,7 +946,10 @@ impl Context {
TyParam::FreeVar(fv) if fv.is_linked() => { TyParam::FreeVar(fv) if fv.is_linked() => {
self.instantiate_tp(fv.crack().clone(), tmp_tv_ctx, loc) self.instantiate_tp(fv.crack().clone(), tmp_tv_ctx, loc)
} }
p @ (TyParam::Value(_) | TyParam::Mono(_) | TyParam::FreeVar(_)) => Ok(p), p @ (TyParam::Value(_)
| TyParam::Mono(_)
| TyParam::FreeVar(_)
| TyParam::Erased(_)) => Ok(p),
other => todo!("{other}"), other => todo!("{other}"),
} }
} }

View file

@ -1922,6 +1922,7 @@ impl Type {
matches!(self, Self::FreeVar(_)) matches!(self, Self::FreeVar(_))
} }
/// FIXME: `Int or Str` should be monomorphic
pub fn is_monomorphic(&self) -> bool { pub fn is_monomorphic(&self) -> bool {
matches!(self.typarams_len(), Some(0) | None) matches!(self.typarams_len(), Some(0) | None)
} }