Skip to content

Commit e4be376

Browse files
committed
comprehension starred expression compatibility
1 parent 09d849a commit e4be376

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler/src/compile.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,21 +2027,33 @@ impl<O: OutputStream> Compiler<O> {
20272027
}
20282028
}
20292029

2030+
let mut compile_element = |element| {
2031+
self.compile_expression(element).map_err(|e| {
2032+
if matches!(e.error, CompileErrorType::InvalidStarExpr) {
2033+
self.error(CompileErrorType::SyntaxError(
2034+
"iterable unpacking cannot be used in comprehension".to_owned(),
2035+
))
2036+
} else {
2037+
e
2038+
}
2039+
})
2040+
};
2041+
20302042
match kind {
20312043
ast::ComprehensionKind::GeneratorExpression { element } => {
2032-
self.compile_expression(element)?;
2044+
compile_element(element)?;
20332045
self.mark_generator();
20342046
self.emit(Instruction::YieldValue);
20352047
self.emit(Instruction::Pop);
20362048
}
20372049
ast::ComprehensionKind::List { element } => {
2038-
self.compile_expression(element)?;
2050+
compile_element(element)?;
20392051
self.emit(Instruction::ListAppend {
20402052
i: 1 + generators.len(),
20412053
});
20422054
}
20432055
ast::ComprehensionKind::Set { element } => {
2044-
self.compile_expression(element)?;
2056+
compile_element(element)?;
20452057
self.emit(Instruction::SetAdd {
20462058
i: 1 + generators.len(),
20472059
});

0 commit comments

Comments
 (0)