92
92
import com .oracle .graal .python .nodes .function .FunctionDefinitionNode ;
93
93
import com .oracle .graal .python .nodes .function .FunctionRootNode ;
94
94
import com .oracle .graal .python .nodes .function .GeneratorFunctionDefinitionNode ;
95
+ import com .oracle .graal .python .nodes .generator .AbstractYieldNode ;
95
96
import com .oracle .graal .python .nodes .generator .GeneratorBlockNode ;
96
97
import com .oracle .graal .python .nodes .generator .GeneratorReturnTargetNode ;
97
98
import com .oracle .graal .python .nodes .generator .ReadGeneratorFrameVariableNode ;
@@ -331,6 +332,7 @@ public PNode visit(AssignmentSSTNode node) {
331
332
public PNode visit (AugAssignmentSSTNode node ) {
332
333
checkCannotAssignTo (node .lhs );
333
334
ExpressionNode lhs = (ExpressionNode ) node .lhs .accept (this );
335
+ checkExpressionAssignable (lhs );
334
336
if (!(lhs instanceof ReadNode )) {
335
337
throw errors .raiseInvalidSyntax (source , createSourceSection (node .startOffset , node .endOffset ), ErrorMessages .ILLEGAL_EXPRESSION_FOR_AUGMENTED_ASSIGNEMNT );
336
338
}
@@ -1366,7 +1368,7 @@ protected StatementNode makeWriteNode(ExpressionNode accept) {
1366
1368
}
1367
1369
}
1368
1370
1369
- private StatementNode createAssignment (ExpressionNode lhs , ExpressionNode rhs ) {
1371
+ private void checkExpressionAssignable (ExpressionNode lhs ) {
1370
1372
if (lhs instanceof ObjectLiteralNode ) {
1371
1373
if (((ObjectLiteralNode ) lhs ).getObject () == PEllipsis .INSTANCE ) {
1372
1374
throw errors .raiseInvalidSyntax (source , lhs .getSourceSection (), ErrorMessages .CANNOT_ASSIGN_TO , "Ellipsis" );
@@ -1387,7 +1389,14 @@ private StatementNode createAssignment(ExpressionNode lhs, ExpressionNode rhs) {
1387
1389
throw errors .raiseInvalidSyntax (source , lhs .getSourceSection (), ErrorMessages .CANNOT_ASSIGN_TO , "set display" );
1388
1390
} else if (lhs instanceof FormatStringLiteralNode ) {
1389
1391
throw errors .raiseInvalidSyntax (source , lhs .getSourceSection (), ErrorMessages .CANNOT_ASSIGN_TO , "f-string expression" );
1390
- } else if (lhs instanceof TupleLiteralNode ) {
1392
+ } else if (lhs instanceof AbstractYieldNode ) {
1393
+ throw errors .raiseInvalidSyntax (source , lhs .getSourceSection (), ErrorMessages .CANNOT_ASSIGN_TO , "yield expression" );
1394
+ }
1395
+ }
1396
+
1397
+ private StatementNode createAssignment (ExpressionNode lhs , ExpressionNode rhs ) {
1398
+ checkExpressionAssignable (lhs );
1399
+ if (lhs instanceof TupleLiteralNode ) {
1391
1400
return createDestructuringAssignment (((TupleLiteralNode ) lhs ).getValues (), rhs );
1392
1401
} else if (lhs instanceof ListLiteralNode ) {
1393
1402
return createDestructuringAssignment (((ListLiteralNode ) lhs ).getValues (), rhs );
0 commit comments