Skip to content

Commit

Permalink
fix: correct invisible import handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed May 27, 2024
1 parent edf2689 commit 4a7f995
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ flexstr.workspace = true
enum-as-inner.workspace = true
peg = "0.8"
hamt-sync = { git = "https://github.com/jac3km4/hamt-sync", rev = "v0.2.6" }
sequence_trie = "0.3"
sequence_trie = { git = "https://github.com/jac3km4/rust_sequence_trie", rev = "a056b4c", features = [
"hashbrown",
] }
walkdir = "2"

[lints]
Expand Down
21 changes: 11 additions & 10 deletions compiler/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ impl SymbolMap {
pub fn populate_import(&self, import: Import, scope: &mut Scope, visibility: Visibility) -> Result<(), Error> {
match import {
Import::Exact(_, path, span) => {
if let Some(symbol) = self.get_symbol(&path).with_span(span)?.visible(visibility) {
if let Some(symbol) = self.get_symbol(&path).and_then(|s| s.visible(visibility)) {
scope.add_symbol(path.last().unwrap(), symbol);
} else {
return Err(Cause::UnresolvedImport(path.render()).with_span(span));
}
}
Import::All(_, path, span) => {
Expand All @@ -85,20 +87,20 @@ impl SymbolMap {
Import::Selected(_, path, names, span) => {
for name in names {
let path = path.with_child(name);
if let Some(symbol) = self.get_symbol(&path).with_span(span)?.visible(visibility) {
if let Some(symbol) = self.get_symbol(&path).and_then(|s| s.visible(visibility)) {
scope.add_symbol(path.last().unwrap(), symbol);
} else {
return Err(Cause::UnresolvedImport(path.render()).with_span(span));
}
}
}
};
Ok(())
}

pub fn get_symbol(&self, path: &ModulePath) -> Result<Symbol, Cause> {
self.symbols
.get(path)
.cloned()
.ok_or_else(|| Cause::UnresolvedImport(path.render()))
#[inline]
pub fn get_symbol(&self, path: &ModulePath) -> Option<Symbol> {
self.symbols.get(path).cloned()
}

fn get_direct_children(&self, path: &ModulePath) -> Result<impl Iterator<Item = (Ident, &Symbol)>, Cause> {
Expand All @@ -107,9 +109,8 @@ impl SymbolMap {
.get_node(path)
.ok_or_else(|| Cause::UnresolvedModule(path.render()))?;
let res = node
.iter()
.filter(|(parts, _)| parts.len() == 1)
.map(|(mut parts, sym)| (parts.pop().unwrap().clone(), sym));
.children_with_keys()
.filter_map(|(k, v)| Some((k.clone(), v.value()?)));
Ok(res)
}
}
Expand Down

0 comments on commit 4a7f995

Please sign in to comment.