mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
chore: fix minor bugs
This commit is contained in:
parent
c8f71d78f9
commit
0b0badfef4
4 changed files with 30 additions and 21 deletions
|
@ -7,7 +7,7 @@ use std::time::SystemTime;
|
|||
|
||||
use erg_common::config::ErgMode;
|
||||
use erg_common::consts::PYTHON_MODE;
|
||||
use erg_common::env::erg_pystd_path;
|
||||
use erg_common::env::is_pystd_main_module;
|
||||
use erg_common::erg_util::BUILTIN_ERG_MODS;
|
||||
use erg_common::levenshtein::get_similar_name;
|
||||
use erg_common::python_util::BUILTIN_PYTHON_MODS;
|
||||
|
@ -1854,18 +1854,6 @@ impl Context {
|
|||
get_similar_name(BUILTIN_ERG_MODS.into_iter(), name).map(Str::rc)
|
||||
}
|
||||
|
||||
fn is_pystd_main_module(&self, path: &Path) -> bool {
|
||||
let mut path = PathBuf::from(path);
|
||||
if path.ends_with("__init__.d.er") {
|
||||
path.pop();
|
||||
path.pop();
|
||||
} else {
|
||||
path.pop();
|
||||
}
|
||||
let pystd_path = erg_pystd_path();
|
||||
path == pystd_path
|
||||
}
|
||||
|
||||
/// e.g. http.d/client.d.er -> http.client
|
||||
/// math.d.er -> math
|
||||
fn mod_name(&self, path: &Path) -> Str {
|
||||
|
@ -1907,7 +1895,7 @@ impl Context {
|
|||
if Self::can_reuse(&path).is_none() {
|
||||
let _ = self.try_gen_py_decl_file(__name__);
|
||||
}
|
||||
if self.is_pystd_main_module(path.as_path())
|
||||
if is_pystd_main_module(path.as_path())
|
||||
&& !BUILTIN_PYTHON_MODS.contains(&&__name__[..])
|
||||
{
|
||||
let err = TyCheckError::module_env_error(
|
||||
|
|
|
@ -2575,6 +2575,13 @@ impl Expr {
|
|||
self.call_expr(Args::single(PosArg::new(expr)))
|
||||
}
|
||||
|
||||
pub fn call2(self, expr1: Expr, expr2: Expr) -> Self {
|
||||
self.call_expr(Args::pos_only(
|
||||
vec![PosArg::new(expr1), PosArg::new(expr2)],
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn attr(self, ident: Identifier) -> Accessor {
|
||||
Accessor::attr(self, ident)
|
||||
}
|
||||
|
|
|
@ -2800,7 +2800,7 @@ impl Type {
|
|||
)
|
||||
}
|
||||
// TODO: consider variances
|
||||
_ => self.clone().replace(&Type::Failure, &Type::Never),
|
||||
_ => self.clone().replace(&Self::Failure, &Self::Never),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2811,17 +2811,20 @@ impl Type {
|
|||
match self {
|
||||
Self::FreeVar(fv) if fv.is_linked() => fv.crack().clone()._replace(target, to),
|
||||
Self::FreeVar(fv) => {
|
||||
let fv = fv.deep_clone();
|
||||
if let Some((sub, sup)) = fv.get_subsup() {
|
||||
let fv_clone = fv.deep_clone();
|
||||
if let Some((sub, sup)) = fv_clone.get_subsup() {
|
||||
fv.dummy_link();
|
||||
fv_clone.dummy_link();
|
||||
let sub = sub._replace(target, to);
|
||||
let sup = sup._replace(target, to);
|
||||
fv.undo();
|
||||
fv.update_constraint(Constraint::new_sandwiched(sub, sup), true);
|
||||
} else if let Some(ty) = fv.get_type() {
|
||||
fv.update_constraint(Constraint::new_type_of(ty._replace(target, to)), true);
|
||||
fv_clone.undo();
|
||||
fv_clone.update_constraint(Constraint::new_sandwiched(sub, sup), true);
|
||||
} else if let Some(ty) = fv_clone.get_type() {
|
||||
fv_clone
|
||||
.update_constraint(Constraint::new_type_of(ty._replace(target, to)), true);
|
||||
}
|
||||
Self::FreeVar(fv)
|
||||
Self::FreeVar(fv_clone)
|
||||
}
|
||||
Self::Refinement(mut refine) => {
|
||||
refine.t = Box::new(refine.t._replace(target, to));
|
||||
|
|
|
@ -4424,6 +4424,17 @@ impl Expr {
|
|||
Self::Call(self.call(args))
|
||||
}
|
||||
|
||||
pub fn call1(self, expr: Expr) -> Self {
|
||||
self.call_expr(Args::pos_only(vec![PosArg::new(expr)], None))
|
||||
}
|
||||
|
||||
pub fn call2(self, expr1: Expr, expr2: Expr) -> Self {
|
||||
self.call_expr(Args::pos_only(
|
||||
vec![PosArg::new(expr1), PosArg::new(expr2)],
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn type_asc(self, t_spec: TypeSpecWithOp) -> TypeAscription {
|
||||
TypeAscription::new(self, t_spec)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue