[fine] Bindings in if remain in scope!
This commit is contained in:
parent
198dc5bdb3
commit
f00b9e22e7
2 changed files with 34 additions and 3 deletions
|
|
@ -433,6 +433,34 @@ fn set_logical_parents(
|
|||
set_logical_parents(parents, syntax_tree, rhs, Some(t));
|
||||
}
|
||||
}
|
||||
TreeKind::ConditionalExpression => {
|
||||
// Special case! If the condition expression is a `is` expression
|
||||
// then it is the parent for the body of the `then` clause so
|
||||
// that any variable bindings it makes remain in scope. The
|
||||
// `else` clause and the condition itself do not have the
|
||||
// bindings in scope, obviously.
|
||||
let body_parent = if let Some(is_condition) =
|
||||
tree.child_of_kind(syntax_tree, TreeKind::IsExpression)
|
||||
{
|
||||
Some(is_condition)
|
||||
} else {
|
||||
Some(t)
|
||||
};
|
||||
|
||||
let then_body = tree.nth_tree(2);
|
||||
for child in &tree.children {
|
||||
match child {
|
||||
Child::Token(_) => (),
|
||||
Child::Tree(ct) => {
|
||||
if Some(*ct) == then_body {
|
||||
set_logical_parents(parents, syntax_tree, *ct, body_parent);
|
||||
} else {
|
||||
set_logical_parents(parents, syntax_tree, *ct, Some(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// By default, the parent for each child is current tree.
|
||||
for child in &tree.children {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue