mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-04 02:39:22 +00:00
Fix scan_expression and compile_dict
This commit is contained in:
parent
375d592562
commit
cb3578dbf2
2 changed files with 14 additions and 13 deletions
|
@ -1992,18 +1992,18 @@ impl Compiler {
|
||||||
values: &[ast::Expr],
|
values: &[ast::Expr],
|
||||||
) -> CompileResult<()> {
|
) -> CompileResult<()> {
|
||||||
let mut size = 0;
|
let mut size = 0;
|
||||||
|
let (packed, unpacked): (Vec<_>, Vec<_>) = keys
|
||||||
let (packed_values, unpacked_values) = values.split_at(keys.len());
|
.iter()
|
||||||
for (key, value) in keys.iter().zip(packed_values) {
|
.zip(values.iter())
|
||||||
if let Some(key) = key {
|
.partition(|(k, _)| k.is_some());
|
||||||
self.compile_expression(key)?;
|
for (key, value) in packed {
|
||||||
}
|
self.compile_expression(&key.as_ref().unwrap())?;
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
size += 1;
|
size += 1;
|
||||||
}
|
}
|
||||||
emit!(self, Instruction::BuildMap { size });
|
emit!(self, Instruction::BuildMap { size });
|
||||||
|
|
||||||
for value in unpacked_values {
|
for (_, value) in unpacked {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
emit!(self, Instruction::DictUpdate);
|
emit!(self, Instruction::DictUpdate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -885,14 +885,15 @@ impl SymbolTableBuilder {
|
||||||
self.scan_expression(value, ExpressionContext::Load)?;
|
self.scan_expression(value, ExpressionContext::Load)?;
|
||||||
}
|
}
|
||||||
Dict { keys, values } => {
|
Dict { keys, values } => {
|
||||||
let (packed, unpacked) = values.split_at(keys.len());
|
let (packed, unpacked): (Vec<_>, Vec<_>) = keys
|
||||||
for (key, value) in keys.iter().zip(packed) {
|
.iter()
|
||||||
if let Some(key) = key {
|
.zip(values.iter())
|
||||||
self.scan_expression(key, context)?;
|
.partition(|(key, _)| key.is_some());
|
||||||
}
|
for (key, value) in packed {
|
||||||
|
self.scan_expression(&key.as_ref().unwrap(), context)?;
|
||||||
self.scan_expression(value, context)?;
|
self.scan_expression(value, context)?;
|
||||||
}
|
}
|
||||||
for value in unpacked {
|
for (_, value) in unpacked {
|
||||||
// dict unpacking marker
|
// dict unpacking marker
|
||||||
self.scan_expression(value, context)?;
|
self.scan_expression(value, context)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue