mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35: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],
|
||||
) -> CompileResult<()> {
|
||||
let mut size = 0;
|
||||
|
||||
let (packed_values, unpacked_values) = values.split_at(keys.len());
|
||||
for (key, value) in keys.iter().zip(packed_values) {
|
||||
if let Some(key) = key {
|
||||
self.compile_expression(key)?;
|
||||
}
|
||||
let (packed, unpacked): (Vec<_>, Vec<_>) = keys
|
||||
.iter()
|
||||
.zip(values.iter())
|
||||
.partition(|(k, _)| k.is_some());
|
||||
for (key, value) in packed {
|
||||
self.compile_expression(&key.as_ref().unwrap())?;
|
||||
self.compile_expression(value)?;
|
||||
size += 1;
|
||||
}
|
||||
emit!(self, Instruction::BuildMap { size });
|
||||
|
||||
for value in unpacked_values {
|
||||
for (_, value) in unpacked {
|
||||
self.compile_expression(value)?;
|
||||
emit!(self, Instruction::DictUpdate);
|
||||
}
|
||||
|
|
|
@ -885,14 +885,15 @@ impl SymbolTableBuilder {
|
|||
self.scan_expression(value, ExpressionContext::Load)?;
|
||||
}
|
||||
Dict { keys, values } => {
|
||||
let (packed, unpacked) = values.split_at(keys.len());
|
||||
for (key, value) in keys.iter().zip(packed) {
|
||||
if let Some(key) = key {
|
||||
self.scan_expression(key, context)?;
|
||||
}
|
||||
let (packed, unpacked): (Vec<_>, Vec<_>) = keys
|
||||
.iter()
|
||||
.zip(values.iter())
|
||||
.partition(|(key, _)| key.is_some());
|
||||
for (key, value) in packed {
|
||||
self.scan_expression(&key.as_ref().unwrap(), context)?;
|
||||
self.scan_expression(value, context)?;
|
||||
}
|
||||
for value in unpacked {
|
||||
for (_, value) in unpacked {
|
||||
// dict unpacking marker
|
||||
self.scan_expression(value, context)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue