Skip to content

Commit

Permalink
chore: fix mod_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jun 19, 2024
1 parent bc23f9d commit 575df74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 16 additions & 2 deletions crates/erg_common/pathutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `/`
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions crates/erg_compiler/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3890,15 +3891,17 @@ 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();
let kw_var_params = subr.kw_var_params.as_ref().map(|pt| {
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);
Expand Down

0 comments on commit 575df74

Please sign in to comment.