fix: eliminate panics

This commit is contained in:
Shunsuke Shibayama 2024-08-28 21:20:13 +09:00
parent caadd3c418
commit fdca32f6a9
5 changed files with 59 additions and 6 deletions

View file

@ -896,6 +896,9 @@ impl Context {
str_.register_py_builtin(OP_GE, fn1_met(Str, Str, Bool), Some(OP_GE), 0);
str_.register_py_builtin(OP_LT, fn1_met(Str, Str, Bool), Some(OP_LT), 0);
str_.register_py_builtin(OP_LE, fn1_met(Str, Str, Bool), Some(OP_LE), 0);
if PYTHON_MODE {
str_.register_py_builtin(OP_MOD, fn1_met(Str, Obj, Str), Some(OP_MOD), 0);
}
str_.register_trait(self, mono(ORD)).unwrap();
str_.register_trait(self, mono(PATH_LIKE)).unwrap();
let t_s_replace = fn_met(

View file

@ -1442,9 +1442,9 @@ impl Context {
let coerced = self
.coerce(obj.t(), &())
.map_err(|mut errs| errs.remove(0))?;
if &coerced != obj.ref_t() {
if &coerced != obj.ref_t() && obj.ref_t().as_free().is_some() {
let hash = get_hash(obj.ref_t());
obj.ref_t().destructive_link(&coerced);
obj.ref_t().destructive_link(&coerced); // obj.ref_t().coerce(None);
if get_hash(obj.ref_t()) != hash {
return self
.search_method_info(obj, attr_name, pos_args, kw_args, input, namespace);
@ -1587,9 +1587,10 @@ impl Context {
let coerced = self
.coerce(obj.t(), &())
.map_err(|mut errs| errs.remove(0))?;
if &coerced != obj.ref_t() {
// REVIEW: if obj.ref_t() is not a free-var but contains free-vars
if &coerced != obj.ref_t() && obj.ref_t().as_free().is_some() {
let hash = get_hash(obj.ref_t());
obj.ref_t().destructive_link(&coerced);
obj.ref_t().destructive_link(&coerced); // obj.ref_t().coerce(None);
if get_hash(obj.ref_t()) != hash {
return self.search_method_info_without_args(obj, attr_name, input, namespace);
}