mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
fix: const call bug
This commit is contained in:
parent
477778c9fe
commit
2ddff1512f
6 changed files with 35 additions and 13 deletions
|
@ -1925,11 +1925,20 @@ impl Context {
|
|||
self.convert_tp_into_type(t)
|
||||
}
|
||||
// TyParam(Ts: Array(Type)) -> Type(Ts: Array(Type))
|
||||
TyParam::FreeVar(fv) if fv.get_type().is_some() => Ok(named_free_var(
|
||||
fv.unbound_name().unwrap(),
|
||||
fv.level().unwrap(),
|
||||
fv.constraint().unwrap(),
|
||||
)),
|
||||
// TyParam(?S(: Str)) -> Err(...),
|
||||
// TyParam(?D(: GenericDict)) -> Ok(?D(: GenericDict)),
|
||||
// FIXME: GenericDict
|
||||
TyParam::FreeVar(fv)
|
||||
if fv.get_type().is_some_and(|t| {
|
||||
self.subtype_of(&t, &Type::Type) || &t.qual_name() == "GenericDict"
|
||||
}) =>
|
||||
{
|
||||
Ok(named_free_var(
|
||||
fv.unbound_name().unwrap(),
|
||||
fv.level().unwrap(),
|
||||
fv.constraint().unwrap(),
|
||||
))
|
||||
}
|
||||
TyParam::Type(t) => Ok(t.as_ref().clone()),
|
||||
TyParam::Mono(name) => Ok(Type::Mono(name)),
|
||||
TyParam::App { name, args } => Ok(Type::Poly { name, params: args }),
|
||||
|
@ -2599,7 +2608,16 @@ impl Context {
|
|||
TyParam::App { ref name, ref args } => self
|
||||
.rec_get_const_obj(name)
|
||||
.and_then(|v| {
|
||||
let ty = self.convert_value_into_type(v.clone()).ok()?;
|
||||
let ty = match self.convert_value_into_type(v.clone()) {
|
||||
Ok(ty) => ty,
|
||||
Err(ValueObj::Subr(subr)) => {
|
||||
// REVIEW: evaluation of polymorphic types
|
||||
return subr.sig_t().return_t().cloned();
|
||||
}
|
||||
Err(_) => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let instance = self
|
||||
.instantiate_def_type(&ty)
|
||||
.map_err(|err| {
|
||||
|
|
|
@ -665,7 +665,7 @@ impl Context {
|
|||
);
|
||||
let patch = ConstSubr::Builtin(BuiltinConstSubr::new(PATCH, patch_func, patch_t, None));
|
||||
self.register_builtin_const(PATCH, vis.clone(), ValueObj::Subr(patch));
|
||||
let t_resolve_path = nd_func(vec![kw(KW_PATH, Str)], None, mono(GENERIC_MODULE));
|
||||
let t_resolve_path = nd_func(vec![kw(KW_PATH, Str)], None, Str);
|
||||
let resolve_path = ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||
FUNC_RESOLVE_PATH,
|
||||
resolve_path_func,
|
||||
|
@ -673,7 +673,7 @@ impl Context {
|
|||
None,
|
||||
));
|
||||
self.register_builtin_const(FUNC_RESOLVE_PATH, vis.clone(), ValueObj::Subr(resolve_path));
|
||||
let t_resolve_decl_path = nd_func(vec![kw(KW_PATH, Str)], None, mono(GENERIC_MODULE));
|
||||
let t_resolve_decl_path = nd_func(vec![kw(KW_PATH, Str)], None, Str);
|
||||
let resolve_decl_path = ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||
FUNC_RESOLVE_DECL_PATH,
|
||||
resolve_decl_path_func,
|
||||
|
|
|
@ -2246,7 +2246,7 @@ impl Context {
|
|||
);
|
||||
log!(info "Substituted:\ninstance: {instance}");
|
||||
debug_assert!(
|
||||
instance.is_type() || instance.has_no_qvar(),
|
||||
self.subtype_of(&instance, &Type::Type) || instance.has_no_qvar(),
|
||||
"{instance} has qvar (obj: {obj}, attr: {}",
|
||||
fmt_option!(attr_name)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue