mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
fix: eliminate panic
s
This commit is contained in:
parent
caadd3c418
commit
fdca32f6a9
5 changed files with 59 additions and 6 deletions
|
@ -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_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_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);
|
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(ORD)).unwrap();
|
||||||
str_.register_trait(self, mono(PATH_LIKE)).unwrap();
|
str_.register_trait(self, mono(PATH_LIKE)).unwrap();
|
||||||
let t_s_replace = fn_met(
|
let t_s_replace = fn_met(
|
||||||
|
|
|
@ -1442,9 +1442,9 @@ impl Context {
|
||||||
let coerced = self
|
let coerced = self
|
||||||
.coerce(obj.t(), &())
|
.coerce(obj.t(), &())
|
||||||
.map_err(|mut errs| errs.remove(0))?;
|
.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());
|
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 {
|
if get_hash(obj.ref_t()) != hash {
|
||||||
return self
|
return self
|
||||||
.search_method_info(obj, attr_name, pos_args, kw_args, input, namespace);
|
.search_method_info(obj, attr_name, pos_args, kw_args, input, namespace);
|
||||||
|
@ -1587,9 +1587,10 @@ impl Context {
|
||||||
let coerced = self
|
let coerced = self
|
||||||
.coerce(obj.t(), &())
|
.coerce(obj.t(), &())
|
||||||
.map_err(|mut errs| errs.remove(0))?;
|
.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());
|
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 {
|
if get_hash(obj.ref_t()) != hash {
|
||||||
return self.search_method_info_without_args(obj, attr_name, input, namespace);
|
return self.search_method_info_without_args(obj, attr_name, input, namespace);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ use crate::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArti
|
||||||
use crate::build_package::CheckStatus;
|
use crate::build_package::CheckStatus;
|
||||||
use crate::module::SharedCompilerResource;
|
use crate::module::SharedCompilerResource;
|
||||||
use crate::ty::constructors::{
|
use crate::ty::constructors::{
|
||||||
free_var, func, guard, list_t, mono, poly, proc, refinement, set_t, singleton, ty_tp,
|
free_var, from_str, func, guard, list_t, mono, poly, proc, refinement, set_t, singleton, ty_tp,
|
||||||
unsized_list_t, v_enum,
|
unsized_list_t, v_enum,
|
||||||
};
|
};
|
||||||
use crate::ty::free::Constraint;
|
use crate::ty::free::Constraint;
|
||||||
|
@ -3074,7 +3074,7 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
||||||
line!() as usize,
|
line!() as usize,
|
||||||
method_name.inspect(),
|
method_name.inspect(),
|
||||||
method_name.loc(),
|
method_name.loc(),
|
||||||
&mono(&sup.name), // TODO: get super type
|
&from_str(&sup.name), // TODO: get super type
|
||||||
self.module.context.caused_by(),
|
self.module.context.caused_by(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -518,6 +518,34 @@ pub fn mono<S: Into<Str>>(name: S) -> Type {
|
||||||
Type::Mono(name)
|
Type::Mono(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_str(name: impl Into<Str>) -> Type {
|
||||||
|
let name = name.into();
|
||||||
|
match &name[..] {
|
||||||
|
"Obj" => Type::Obj,
|
||||||
|
"Int" => Type::Int,
|
||||||
|
"Nat" => Type::Nat,
|
||||||
|
"Ratio" => Type::Ratio,
|
||||||
|
"Float" => Type::Float,
|
||||||
|
"Complex" => Type::Complex,
|
||||||
|
"Bool" => Type::Bool,
|
||||||
|
"Str" => Type::Str,
|
||||||
|
"NoneType" => Type::NoneType,
|
||||||
|
"Code" => Type::Code,
|
||||||
|
"Frame" => Type::Frame,
|
||||||
|
"Error" => Type::Error,
|
||||||
|
"Inf" => Type::Inf,
|
||||||
|
"NegInf" => Type::NegInf,
|
||||||
|
"Type" => Type::Type,
|
||||||
|
"ClassType" => Type::ClassType,
|
||||||
|
"TraitType" => Type::TraitType,
|
||||||
|
"Patch" => Type::Patch,
|
||||||
|
"NotImplementedType" => Type::NotImplementedType,
|
||||||
|
"Ellipsis" => Type::Ellipsis,
|
||||||
|
"Never" => Type::Never,
|
||||||
|
_ => Type::Mono(name),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn poly<S: Into<Str>>(name: S, params: Vec<TyParam>) -> Type {
|
pub fn poly<S: Into<Str>>(name: S, params: Vec<TyParam>) -> Type {
|
||||||
Type::Poly {
|
Type::Poly {
|
||||||
|
|
|
@ -886,6 +886,25 @@ impl SubrType {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn destructive_coerce(&self) {
|
||||||
|
for nd in self.non_default_params.iter() {
|
||||||
|
nd.typ().destructive_coerce();
|
||||||
|
}
|
||||||
|
if let Some(var) = self.var_params.as_ref() {
|
||||||
|
var.typ().destructive_coerce();
|
||||||
|
}
|
||||||
|
for d in self.default_params.iter() {
|
||||||
|
d.typ().destructive_coerce();
|
||||||
|
if let Some(default) = d.default_typ() {
|
||||||
|
default.destructive_coerce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(kw_var) = self.kw_var_params.as_ref() {
|
||||||
|
kw_var.typ().destructive_coerce();
|
||||||
|
}
|
||||||
|
self.return_t.destructive_coerce();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -3307,6 +3326,8 @@ impl Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Type::Subr(subr) => subr.destructive_coerce(),
|
||||||
|
// TODO:
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue