Fix crash on missing parent

This commit is contained in:
Charlie Marsh 2022-09-07 22:40:25 -04:00
parent 2ac5c830c1
commit a8f4faa6e4
2 changed files with 16 additions and 9 deletions

View file

@ -500,10 +500,12 @@ 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));
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),
},
ExprKind::Call { func, .. } => {
@ -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,
@ -781,12 +783,14 @@ where
ctx: ExprContext::Store,
},
),
Some(parent),
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();
@ -798,9 +802,11 @@ where
ctx: ExprContext::Store,
},
),
Some(parent),
parent,
);
if let Some(parent) = parent {
self.parents.push(parent);
}
walk_excepthandler(self, excepthandler);

View file

@ -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)?;