File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2027,21 +2027,33 @@ impl<O: OutputStream> Compiler<O> {
2027
2027
}
2028
2028
}
2029
2029
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
+
2030
2042
match kind {
2031
2043
ast:: ComprehensionKind :: GeneratorExpression { element } => {
2032
- self . compile_expression ( element) ?;
2044
+ compile_element ( element) ?;
2033
2045
self . mark_generator ( ) ;
2034
2046
self . emit ( Instruction :: YieldValue ) ;
2035
2047
self . emit ( Instruction :: Pop ) ;
2036
2048
}
2037
2049
ast:: ComprehensionKind :: List { element } => {
2038
- self . compile_expression ( element) ?;
2050
+ compile_element ( element) ?;
2039
2051
self . emit ( Instruction :: ListAppend {
2040
2052
i : 1 + generators. len ( ) ,
2041
2053
} ) ;
2042
2054
}
2043
2055
ast:: ComprehensionKind :: Set { element } => {
2044
- self . compile_expression ( element) ?;
2056
+ compile_element ( element) ?;
2045
2057
self . emit ( Instruction :: SetAdd {
2046
2058
i : 1 + generators. len ( ) ,
2047
2059
} ) ;
You can’t perform that action at this time.
0 commit comments