mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-14 00:25:17 +00:00
Fix with-statement location
This commit is contained in:
parent
75b886bcd6
commit
a9306971ae
1 changed files with 5 additions and 0 deletions
|
@ -1393,12 +1393,15 @@ impl Compiler {
|
|||
body: &[ast::Stmt],
|
||||
is_async: bool,
|
||||
) -> CompileResult<()> {
|
||||
let with_location = self.current_source_location;
|
||||
|
||||
let end_blocks = items
|
||||
.iter()
|
||||
.map(|item| {
|
||||
let end_block = self.new_block();
|
||||
self.compile_expression(&item.context_expr)?;
|
||||
|
||||
self.set_source_location(with_location);
|
||||
if is_async {
|
||||
self.emit(Instruction::BeforeAsyncWith);
|
||||
self.emit(Instruction::GetAwaitable);
|
||||
|
@ -1411,6 +1414,7 @@ impl Compiler {
|
|||
|
||||
match &item.optional_vars {
|
||||
Some(var) => {
|
||||
self.set_source_location(var.location);
|
||||
self.compile_store(var)?;
|
||||
}
|
||||
None => {
|
||||
|
@ -1425,6 +1429,7 @@ impl Compiler {
|
|||
|
||||
// sort of "stack up" the layers of with blocks:
|
||||
// with a, b: body -> start_with(a) start_with(b) body() end_with(b) end_with(a)
|
||||
self.set_source_location(with_location);
|
||||
for end_block in end_blocks.into_iter().rev() {
|
||||
self.emit(Instruction::PopBlock);
|
||||
self.emit(Instruction::EnterFinally);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue