From 575df7485a8ec20f8233b29e383cddd21b1760e0 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Wed, 19 Jun 2024 16:28:48 +0900 Subject: [PATCH] chore: fix `mod_name` --- crates/erg_common/pathutil.rs | 18 ++++++++++++++++-- crates/erg_compiler/ty/mod.rs | 7 +++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/erg_common/pathutil.rs b/crates/erg_common/pathutil.rs index 26dab295a..76f2a6bfc 100644 --- a/crates/erg_common/pathutil.rs +++ b/crates/erg_common/pathutil.rs @@ -241,6 +241,7 @@ pub fn remove_verbatim(path: &Path) -> String { /// $ERG_PATH/pkgs/certified/torch/1.0.0/src/lib.d.er -> torch /// $ERG_PATH/pkgs/certified/torch/1.0.0/src/random.d.er -> torch/random /// /users/foo/torch/src/lib.d.er -> torch +/// foo/__pycache__/__init__.d.er -> foo /// math.d.er -> math /// ``` /// FIXME: split by `.` instead of `/` @@ -303,9 +304,22 @@ pub fn mod_name(path: &Path) -> Str { .to_string_lossy() .trim_end_matches(".d.er") .to_string(); - for parent in path.components().rev().skip(1) { + let mut parents = path.components().rev().skip(1); + while let Some(parent) = parents.next() { let parent = parent.as_os_str().to_string_lossy(); - if parent.ends_with(".d") { + if parent == "__pycache__" { + if name == "__init__" { + let p = parents + .next() + .unwrap() + .as_os_str() + .to_string_lossy() + .trim_end_matches(".d") + .to_string(); + name = p; + } + break; + } else if parent.ends_with(".d") { let p = parent.trim_end_matches(".d").to_string(); if name == "__init__" { name = p; diff --git a/crates/erg_compiler/ty/mod.rs b/crates/erg_compiler/ty/mod.rs index cd6314763..b4e6c6228 100644 --- a/crates/erg_compiler/ty/mod.rs +++ b/crates/erg_compiler/ty/mod.rs @@ -3870,6 +3870,7 @@ impl Type { pub fn replace_failure_type(&self) -> Type { match self { Self::Quantified(quant) => quant.replace_failure().quantify(), + // consider variances Self::Subr(subr) => { let non_default_params = subr .non_default_params @@ -3890,7 +3891,8 @@ impl Type { pt.clone() .map_type(|t| t.replace(&Self::Failure, &Self::Obj)) .map_default_type(|t| { - t.replace(&Self::Failure, pt.typ()) & pt.typ().clone() + let typ = pt.typ().clone().replace(&Self::Failure, &Self::Obj); + t.replace(&Self::Failure, &typ) & typ }) }) .collect(); @@ -3898,7 +3900,8 @@ impl Type { pt.clone() .map_type(|t| t.replace(&Self::Failure, &Self::Obj)) .map_default_type(|t| { - t.replace(&Self::Failure, pt.typ()) & pt.typ().clone() + let typ = pt.typ().clone().replace(&Self::Failure, &Self::Obj); + t.replace(&Self::Failure, &typ) & typ }) }); let return_t = subr.return_t.clone().replace(&Self::Failure, &Self::Never);