Merge pull request #184 from Aralox/Issue-183-support-unpack-empty

Support unpacking empty list.
This commit is contained in:
Michael Hansen
2020-10-24 14:15:47 -07:00
committed by GitHub
5 changed files with 29 additions and 4 deletions

View File

@@ -2243,10 +2243,23 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
case Pyc::UNPACK_SEQUENCE_A:
{
unpack = operand;
ASTTuple::value_t vals;
stack.push(new ASTTuple(vals));
if (unpack > 0) {
ASTTuple::value_t vals;
stack.push(new ASTTuple(vals));
} else {
// Unpack zero values and assign it to top of stack or for loop variable.
// E.g. [] = TOS / for [] in X
ASTTuple::value_t vals;
auto tup = new ASTTuple(vals);
if (curblock->blktype() == ASTBlock::BLK_FOR
&& !curblock->inited()) {
tup->setRequireParens(true);
curblock.cast<ASTIterBlock>()->setIndex(tup);
} else {
curblock->append(new ASTStore(stack.top(), tup));
stack.pop();
}
}
}
break;
case Pyc::YIELD_FROM:

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,5 @@
[] = c
y = []
for [] in x:
BLOCK
[] = []

View File

@@ -0,0 +1,7 @@
( ) = c <EOL>
y = [ ] <EOL>
for ( ) in x : <EOL>
<INDENT>
BLOCK <EOL>
<OUTDENT>
( ) = [ ] <EOL>