Fixes PY-253: foo[1]=2 now has foo as reference, not target

This commit is contained in:
Dmitry Cheryasov
2009-12-19 06:32:10 +02:00
parent 6893ed790f
commit 8f80611a9c
4 changed files with 25 additions and 0 deletions

View File

@@ -257,6 +257,11 @@ public class ExpressionParsing extends Parsing {
else {
checkMatches(PyTokenTypes.RBRACKET, message("PARSE.expected.rbracket"));
expr.done(PyElementTypes.SUBSCRIPTION_EXPRESSION);
if (first_identifier_is_target) {
recast_first_identifier = true; // subscription is always a reference
expr.rollbackTo();
break;
}
}
}
expr = expr.precede();
@@ -265,6 +270,7 @@ public class ExpressionParsing extends Parsing {
expr.drop();
break;
}
recast_first_identifier = false; // it is true only after a break; normal flow always unsets it.
}
}
while (recast_first_identifier);

View File

@@ -0,0 +1 @@
a[1] = 2

View File

@@ -0,0 +1,14 @@
PyFile:SubscribedAssignmentLHS.py(0,8)
PyAssignmentStatement(0,8)
PySubscriptionExpression(0,4)
PyReferenceExpression: a(0,1)
PsiElement(Py:IDENTIFIER)('a')(0,1)
PsiElement(Py:LBRACKET)('[')(1,2)
PyNumericLiteralExpression(2,3)
PsiElement(Py:INTEGER_LITERAL)('1')(2,3)
PsiElement(Py:RBRACKET)(']')(3,4)
PsiWhiteSpace(' ')(4,5)
PsiElement(Py:EQ)('=')(5,6)
PsiWhiteSpace(' ')(6,7)
PyNumericLiteralExpression(7,8)
PsiElement(Py:INTEGER_LITERAL)('2')(7,8)

View File

@@ -26,6 +26,10 @@ public class PythonParsingTest extends ParsingTestCase {
doTest(true);
}
public void testSubscribedAssignmentLHS() throws Exception {
doTest(true);
}
public void testConditionalParenLambda() throws Exception {
doTest(true);
}