Skip to content

Commit

Permalink
Fixed return statements traversal + added unnamed node traversal in c…
Browse files Browse the repository at this point in the history
…ompound statement
  • Loading branch information
SpontanCombust committed Aug 22, 2024
1 parent 0eb0562 commit 745699e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/analysis/src/jobs/scan_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
fn visit_compound_stmt(&mut self, _: &CompoundStatementNode, _: &TraversalContextStack) -> CompoundStatementTraversalPolicy {
CompoundStatementTraversalPolicy {
traverse_statements: true,
traverse_unnamed: false,
traverse_errors: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ impl SyntaxNodeVisitor for ContextualSyntaxAnalysis<'_> {

CompoundStatementTraversalPolicy {
traverse_statements: true,
traverse_unnamed: false,
traverse_errors: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ impl SyntaxNodeVisitor for SyntaxErrorVisitor<'_> {

CompoundStatementTraversalPolicy {
traverse_statements: any_error,
traverse_unnamed: any_error,
traverse_errors: any_error
}
}
Expand Down
11 changes: 7 additions & 4 deletions crates/core/src/ast/misc_stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl SyntaxNodeTraversal for ReturnStatementNode<'_> {

for ch in self.children_detailed() {
match ch {
Ok((value, _)) if tp.traverse_value => {
Ok((value, _)) if value.is_named() && tp.traverse_value => {
let value: ExpressionNode = value.unsafe_into();
value.accept(visitor, ctx);
},
Expand Down Expand Up @@ -283,13 +283,16 @@ impl SyntaxNodeTraversal for CompoundStatementNode<'_> {
if tp.any() {
ctx.push(TraversalContext::CompoundStatement);

for ch in self.children_detailed().must_be_named(true) {
for ch in self.children_detailed() {
match ch {
Ok((stmt, _)) if tp.traverse_statements => {
Ok((stmt, _)) if stmt.is_named() && tp.traverse_statements => {
let stmt: FunctionStatementNode = stmt.unsafe_into();

stmt.accept(visitor, ctx);
},
Ok((unnamed, _)) if !unnamed.is_named() && tp.traverse_unnamed => {
let unnamed: UnnamedNode = unnamed.unsafe_into();
unnamed.accept(visitor, ctx);
},
Err(e) if tp.traverse_errors => {
e.accept(visitor, ctx);
},
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/ast/traversal/policies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ traversal_policy!(ContinueStatementTraversalPolicy,

traversal_policy!(CompoundStatementTraversalPolicy,
traverse_statements,
traverse_unnamed,
traverse_errors
);

Expand Down

0 comments on commit 745699e

Please sign in to comment.