Skip to content

Commit bccebea

Browse files
committed
fix: import resolution bug
1 parent 1d16dd7 commit bccebea

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

crates/erg_compiler/build_package.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,16 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
691691
return Ok(());
692692
}
693693
let path = Path::new(&__name__[..]);
694-
let import_path = match cfg.input.resolve_path(path, cfg) {
694+
let resolved = if call.additional_operation().unwrap().is_erg_import() {
695+
cfg.input
696+
.resolve_real_path(path, cfg)
697+
.or_else(|| cfg.input.resolve_decl_path(path, cfg))
698+
} else {
699+
cfg.input
700+
.resolve_decl_path(path, cfg)
701+
.or_else(|| cfg.input.resolve_real_path(path, cfg))
702+
};
703+
let import_path = match resolved {
695704
Some(path) => path,
696705
None if ERG_MODE => {
697706
for _ in 0..600 {

crates/erg_parser/ast.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,22 @@ impl Accessor {
872872
}
873873
}
874874

875+
pub fn full_name(&self) -> Option<Str> {
876+
match self {
877+
Self::Ident(ident) => Some(ident.inspect().clone()),
878+
Self::Attr(attr) => Some(
879+
format!(
880+
"{}{}{}",
881+
attr.obj.full_name()?,
882+
attr.ident.vis,
883+
attr.ident.inspect()
884+
)
885+
.into(),
886+
),
887+
_ => None,
888+
}
889+
}
890+
875891
pub fn is_const(&self) -> bool {
876892
match self {
877893
Self::Ident(ident) => ident.is_const(),
@@ -6099,6 +6115,15 @@ impl Expr {
60996115
pub fn get_name(&self) -> Option<&Str> {
61006116
match self {
61016117
Expr::Accessor(acc) => acc.name(),
6118+
Expr::TypeAscription(ascription) => ascription.expr.get_name(),
6119+
_ => None,
6120+
}
6121+
}
6122+
6123+
pub fn full_name(&self) -> Option<Str> {
6124+
match self {
6125+
Expr::Accessor(acc) => acc.full_name(),
6126+
Expr::TypeAscription(ascription) => ascription.expr.full_name(),
61026127
_ => None,
61036128
}
61046129
}

0 commit comments

Comments
 (0)