mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 18:45:23 +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],
|
body: &[ast::Stmt],
|
||||||
is_async: bool,
|
is_async: bool,
|
||||||
) -> CompileResult<()> {
|
) -> CompileResult<()> {
|
||||||
|
let with_location = self.current_source_location;
|
||||||
|
|
||||||
let end_blocks = items
|
let end_blocks = items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
let end_block = self.new_block();
|
let end_block = self.new_block();
|
||||||
self.compile_expression(&item.context_expr)?;
|
self.compile_expression(&item.context_expr)?;
|
||||||
|
|
||||||
|
self.set_source_location(with_location);
|
||||||
if is_async {
|
if is_async {
|
||||||
self.emit(Instruction::BeforeAsyncWith);
|
self.emit(Instruction::BeforeAsyncWith);
|
||||||
self.emit(Instruction::GetAwaitable);
|
self.emit(Instruction::GetAwaitable);
|
||||||
|
@ -1411,6 +1414,7 @@ impl Compiler {
|
||||||
|
|
||||||
match &item.optional_vars {
|
match &item.optional_vars {
|
||||||
Some(var) => {
|
Some(var) => {
|
||||||
|
self.set_source_location(var.location);
|
||||||
self.compile_store(var)?;
|
self.compile_store(var)?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -1425,6 +1429,7 @@ impl Compiler {
|
||||||
|
|
||||||
// sort of "stack up" the layers of with blocks:
|
// 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)
|
// 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() {
|
for end_block in end_blocks.into_iter().rev() {
|
||||||
self.emit(Instruction::PopBlock);
|
self.emit(Instruction::PopBlock);
|
||||||
self.emit(Instruction::EnterFinally);
|
self.emit(Instruction::EnterFinally);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue