Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit ba6e68c

Browse files
author
Hendrik van Antwerpen
committed
Ensure symbol scopes are of the right type
1 parent f96536e commit ba6e68c

File tree

1 file changed

+19
-0
lines changed
  • tree-sitter-stack-graphs/src

1 file changed

+19
-0
lines changed

tree-sitter-stack-graphs/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ pub enum LoadError {
679679
ConversionError(String, String, String),
680680
#[error(transparent)]
681681
LanguageError(#[from] tree_sitter::LanguageError),
682+
#[error("Expected exported symbol scope in {0}, got {1}")]
683+
SymbolScopeError(String, String),
682684
}
683685

684686
impl From<stack_graphs::CancellationError> for LoadError {
@@ -738,6 +740,10 @@ impl<'a> Builder<'a> {
738740
self.load_debug_info(node_ref, handle)?;
739741
}
740742

743+
for node in self.stack_graph.nodes_for_file(self.file) {
744+
self.verify_node(node)?;
745+
}
746+
741747
// Then add stack graph edges for each TSG edge. Note that we _don't_ skip(...) here because
742748
// there might be outgoing nodes from the “root” node that we need to process.
743749
// (Technically the caller could add outgoing nodes from “jump to scope” as well, but those
@@ -784,6 +790,19 @@ impl<'a> Builder<'a> {
784790
return Err(LoadError::UnknownNodeType(format!("{}", node_type)));
785791
}
786792
}
793+
794+
fn verify_node(&self, node: Handle<Node>) -> Result<(), LoadError> {
795+
if let Node::PushScopedSymbol(node) = &self.stack_graph[node] {
796+
let scope = &self.stack_graph[self.stack_graph.node_for_id(node.scope).unwrap()];
797+
if !scope.is_exported_scope() {
798+
return Err(LoadError::SymbolScopeError(
799+
format!("{}", node.display(self.stack_graph)),
800+
format!("{}", scope.display(self.stack_graph)),
801+
));
802+
}
803+
}
804+
Ok(())
805+
}
787806
}
788807

789808
enum NodeType {

0 commit comments

Comments
 (0)