mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Fix crash on missing parent
This commit is contained in:
parent
2ac5c830c1
commit
a8f4faa6e4
2 changed files with 16 additions and 9 deletions
|
@ -500,10 +500,12 @@ where
|
||||||
ExprKind::Name { ctx, .. } => match ctx {
|
ExprKind::Name { ctx, .. } => match ctx {
|
||||||
ExprContext::Load => self.handle_node_load(expr),
|
ExprContext::Load => self.handle_node_load(expr),
|
||||||
ExprContext::Store => {
|
ExprContext::Store => {
|
||||||
let parent = self.parents.pop().expect("No parnet statement found.");
|
let parent = self.parents.pop();
|
||||||
self.handle_node_store(expr, Some(parent));
|
self.handle_node_store(expr, parent);
|
||||||
|
if let Some(parent) = parent {
|
||||||
self.parents.push(parent);
|
self.parents.push(parent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ExprContext::Del => self.handle_node_delete(expr),
|
ExprContext::Del => self.handle_node_delete(expr),
|
||||||
},
|
},
|
||||||
ExprKind::Call { func, .. } => {
|
ExprKind::Call { func, .. } => {
|
||||||
|
@ -772,7 +774,7 @@ where
|
||||||
let scope =
|
let scope =
|
||||||
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
|
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
|
||||||
if scope.values.contains_key(name) {
|
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(
|
self.handle_node_store(
|
||||||
&Expr::new(
|
&Expr::new(
|
||||||
excepthandler.location,
|
excepthandler.location,
|
||||||
|
@ -781,12 +783,14 @@ where
|
||||||
ctx: ExprContext::Store,
|
ctx: ExprContext::Store,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Some(parent),
|
parent,
|
||||||
);
|
);
|
||||||
|
if let Some(parent) = parent {
|
||||||
self.parents.push(parent);
|
self.parents.push(parent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let parent = self.parents.pop().expect("No parnet statement found.");
|
let parent = self.parents.pop();
|
||||||
let scope =
|
let scope =
|
||||||
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
|
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))];
|
||||||
let definition = scope.values.get(name).cloned();
|
let definition = scope.values.get(name).cloned();
|
||||||
|
@ -798,9 +802,11 @@ where
|
||||||
ctx: ExprContext::Store,
|
ctx: ExprContext::Store,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Some(parent),
|
parent,
|
||||||
);
|
);
|
||||||
|
if let Some(parent) = parent {
|
||||||
self.parents.push(parent);
|
self.parents.push(parent);
|
||||||
|
}
|
||||||
|
|
||||||
walk_excepthandler(self, excepthandler);
|
walk_excepthandler(self, excepthandler);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::settings::Settings;
|
||||||
use crate::{autofix, cache, fs};
|
use crate::{autofix, cache, fs};
|
||||||
|
|
||||||
fn check_path(path: &Path, settings: &Settings, autofix: &autofix::Mode) -> Result<Vec<Check>> {
|
fn check_path(path: &Path, settings: &Settings, autofix: &autofix::Mode) -> Result<Vec<Check>> {
|
||||||
|
println!("{:?}", path);
|
||||||
// Read the file from disk.
|
// Read the file from disk.
|
||||||
let contents = fs::read_file(path)?;
|
let contents = fs::read_file(path)?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue