Skip to content

Commit

Permalink
fix: import resolution bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Oct 5, 2024
1 parent 1d16dd7 commit bccebea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/erg_compiler/build_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,16 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
return Ok(());
}
let path = Path::new(&__name__[..]);
let import_path = match cfg.input.resolve_path(path, cfg) {
let resolved = if call.additional_operation().unwrap().is_erg_import() {
cfg.input
.resolve_real_path(path, cfg)
.or_else(|| cfg.input.resolve_decl_path(path, cfg))
} else {
cfg.input
.resolve_decl_path(path, cfg)
.or_else(|| cfg.input.resolve_real_path(path, cfg))
};
let import_path = match resolved {
Some(path) => path,
None if ERG_MODE => {
for _ in 0..600 {
Expand Down
25 changes: 25 additions & 0 deletions crates/erg_parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,22 @@ impl Accessor {
}
}

pub fn full_name(&self) -> Option<Str> {
match self {
Self::Ident(ident) => Some(ident.inspect().clone()),
Self::Attr(attr) => Some(
format!(
"{}{}{}",
attr.obj.full_name()?,
attr.ident.vis,
attr.ident.inspect()
)
.into(),
),
_ => None,
}
}

pub fn is_const(&self) -> bool {
match self {
Self::Ident(ident) => ident.is_const(),
Expand Down Expand Up @@ -6099,6 +6115,15 @@ impl Expr {
pub fn get_name(&self) -> Option<&Str> {
match self {
Expr::Accessor(acc) => acc.name(),
Expr::TypeAscription(ascription) => ascription.expr.get_name(),
_ => None,
}
}

pub fn full_name(&self) -> Option<Str> {
match self {
Expr::Accessor(acc) => acc.full_name(),
Expr::TypeAscription(ascription) => ascription.expr.full_name(),
_ => None,
}
}
Expand Down

0 comments on commit bccebea

Please sign in to comment.