Skip to content

Commit

Permalink
Fix crash on missing parent
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 8, 2022
1 parent 2ac5c83 commit a8f4faa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/check_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,11 @@ where
ExprKind::Name { ctx, .. } => match ctx {
ExprContext::Load => self.handle_node_load(expr),
ExprContext::Store => {
let parent = self.parents.pop().expect("No parnet statement found.");
self.handle_node_store(expr, Some(parent));
self.parents.push(parent);
let parent = self.parents.pop();
self.handle_node_store(expr, parent);
if let Some(parent) = parent {
self.parents.push(parent);
}
}
ExprContext::Del => self.handle_node_delete(expr),
},
Expand Down Expand Up @@ -772,7 +774,7 @@ where
let scope =
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
if scope.values.contains_key(name) {
let parent = self.parents.pop().expect("No parnet statement found.");
let parent = self.parents.pop();
self.handle_node_store(
&Expr::new(
excepthandler.location,
Expand All @@ -781,12 +783,14 @@ where
ctx: ExprContext::Store,
},
),
Some(parent),
parent,
);
self.parents.push(parent);
if let Some(parent) = parent {
self.parents.push(parent);
}
}

let parent = self.parents.pop().expect("No parnet statement found.");
let parent = self.parents.pop();
let scope =
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
let definition = scope.values.get(name).cloned();
Expand All @@ -798,9 +802,11 @@ where
ctx: ExprContext::Store,
},
),
Some(parent),
parent,
);
self.parents.push(parent);
if let Some(parent) = parent {
self.parents.push(parent);
}

walk_excepthandler(self, excepthandler);

Expand Down
1 change: 1 addition & 0 deletions src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::settings::Settings;
use crate::{autofix, cache, fs};

fn check_path(path: &Path, settings: &Settings, autofix: &autofix::Mode) -> Result<Vec<Check>> {
println!("{:?}", path);
// Read the file from disk.
let contents = fs::read_file(path)?;

Expand Down

0 comments on commit a8f4faa

Please sign in to comment.