Skip to content

Commit

Permalink
Work in all scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Jun 5, 2024
1 parent eecc2af commit 3661066
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import typing
from typing import cast

# TODO: Figure this out
# for global_var in []:
# _ = global_var
# pass
for global_var in []:
_ = global_var
pass

# _ = global_var
_ = global_var

def foo():
# For control var used outside block
Expand All @@ -16,7 +15,7 @@ def foo():

_ = event

# # Tuple destructuring
# Tuple destructuring
for a, b, c in []:
pass

Expand All @@ -25,7 +24,7 @@ def foo():
_ = c


# # Array destructuring
# Array destructuring
for [d, e, f] in []:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,20 @@ pub(crate) fn control_var_used_after_block(
// return;
// }

println!("nodes {:#?}", checker.semantic().nodes());
// println!("nodes {:#?}", checker.semantic().nodes());

for (name, binding) in scope
.bindings()
.map(|(name, binding_id)| (name, checker.semantic().binding(binding_id)))
// .filter_map(|(name, binding)| {
// if (binding.kind.is_assignment()
// || binding.kind.is_named_expr_assignment()
// || binding.kind.is_with_item_var())
// && (!binding.is_unpacked_assignment() || checker.settings.preview.is_enabled())
// && !binding.is_nonlocal()
// && !binding.is_global()
// && !binding.is_used()
// && !checker.settings.dummy_variable_rgx.is_match(name)
// && !matches!(
// name,
// "__tracebackhide__"
// | "__traceback_info__"
// | "__traceback_supplement__"
// | "__debuggerskip__"
// )
// {
// return Some((name, binding));
// }

// None
// })
.filter_map(|(name, binding)| {
println!("name={:?} kind={:?}", name, binding.kind);

if binding.kind.is_loop_var() || binding.kind.is_with_item_var() {
return Some((name, binding));
}

None
})
{
println!("Binding {:?} {:?}", name, binding);
// Find for-loop variable bindings
Expand Down Expand Up @@ -175,7 +162,7 @@ pub(crate) fn control_var_used_after_block(
"\t\tbinding_source_node_id={:?} binding_statement_id={:?} ancestor_node_id={:?}",
binding_source_node_id, binding_statement_id, ancestor_node_id
);
if (binding_statement_id == ancestor_node_id) {
if binding_statement_id == ancestor_node_id {
println!("\t\to");
found_match = true;
break;
Expand All @@ -184,7 +171,7 @@ pub(crate) fn control_var_used_after_block(
}
}

if (!found_match) {
if !found_match {
println!("\t\temits error={:?}", reference_node_id);
let block_kind = match binding_statement {
Stmt::For(_) => BlockKind::For,
Expand All @@ -197,7 +184,7 @@ pub(crate) fn control_var_used_after_block(
diagnostics.push(Diagnostic::new(
ControlVarUsedAfterBlock {
control_var_name: name.to_owned(),
block_kind: block_kind,
block_kind,
},
reference.range(),
))
Expand Down

0 comments on commit 3661066

Please sign in to comment.