Skip to content

Commit c31e930

Browse files
committed
fix: infinite recursion bugs
1 parent 4af0c4c commit c31e930

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

crates/erg_compiler/context/eval.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ impl Context {
13371337
}
13381338
TyParam::FreeVar(fv) if fv.is_linked() => self.convert_tp_into_type(fv.crack().clone()),
13391339
TyParam::Type(t) => Ok(t.as_ref().clone()),
1340+
TyParam::Mono(name) => Ok(Type::Mono(name)),
1341+
// TyParam::Erased(_t) => Ok(Type::Obj),
13401342
TyParam::Value(v) => self.convert_value_into_type(v).map_err(TyParam::Value),
13411343
// TODO: Dict, Set
13421344
other => Err(other),
@@ -1672,7 +1674,7 @@ impl Context {
16721674
line!() as usize,
16731675
().loc(),
16741676
self.caused_by(),
1675-
&tp.qual_name().unwrap_or("_".into()),
1677+
&tp.to_string(),
16761678
)
16771679
})?;
16781680
if qt.is_generalized() {

crates/erg_compiler/context/inquire.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use std::path::{Path, PathBuf};
44

55
use erg_common::config::Input;
66
use erg_common::consts::{ERG_MODE, PYTHON_MODE};
7-
use erg_common::dict;
87
use erg_common::error::{ErrorCore, Location, SubMessage};
98
use erg_common::levenshtein;
109
use erg_common::set::Set;
1110
use erg_common::traits::{Locational, NoTypeDisplay, Stream};
1211
use erg_common::triple::Triple;
1312
use erg_common::Str;
14-
use erg_common::{fmt_option, fmt_slice, log, option_enum_unwrap, set, switch_lang};
13+
use erg_common::{
14+
dict, fmt_option, fmt_slice, get_hash, log, option_enum_unwrap, set, switch_lang,
15+
};
1516

1617
use erg_parser::ast::{self, Identifier, VarName};
1718
use erg_parser::token::Token;
@@ -1024,20 +1025,23 @@ impl Context {
10241025
let coerced = self
10251026
.coerce(obj.t(), &())
10261027
.map_err(|mut errs| errs.remove(0))?;
1027-
if &coerced == obj.ref_t() {
1028-
Err(TyCheckError::no_attr_error(
1029-
self.cfg.input.clone(),
1030-
line!() as usize,
1031-
attr_name.loc(),
1032-
namespace.name.to_string(),
1033-
obj.ref_t(),
1034-
attr_name.inspect(),
1035-
self.get_similar_attr(obj.ref_t(), attr_name.inspect()),
1036-
))
1037-
} else {
1028+
if &coerced != obj.ref_t() {
1029+
let hash = get_hash(obj.ref_t());
10381030
obj.ref_t().coerce();
1039-
self.search_method_info(obj, attr_name, pos_args, kw_args, input, namespace)
1031+
if get_hash(obj.ref_t()) != hash {
1032+
return self
1033+
.search_method_info(obj, attr_name, pos_args, kw_args, input, namespace);
1034+
}
10401035
}
1036+
Err(TyCheckError::no_attr_error(
1037+
self.cfg.input.clone(),
1038+
line!() as usize,
1039+
attr_name.loc(),
1040+
namespace.name.to_string(),
1041+
obj.ref_t(),
1042+
attr_name.inspect(),
1043+
self.get_similar_attr(obj.ref_t(), attr_name.inspect()),
1044+
))
10411045
}
10421046

10431047
fn validate_visibility(
@@ -1263,12 +1267,13 @@ impl Context {
12631267
return Err(self.not_callable_error(obj, attr_name, instance, None));
12641268
}
12651269
if sub != Never {
1270+
let hash = get_hash(instance);
12661271
instance.coerce();
12671272
if instance.is_quantified_subr() {
12681273
let instance = self.instantiate(instance.clone(), obj)?;
12691274
self.substitute_call(obj, attr_name, &instance, pos_args, kw_args)?;
12701275
return Ok(SubstituteResult::Coerced(instance));
1271-
} else {
1276+
} else if get_hash(instance) != hash {
12721277
return self
12731278
.substitute_call(obj, attr_name, instance, pos_args, kw_args);
12741279
}

0 commit comments

Comments
 (0)