Commit cabf41fb authored by Francis Herne's avatar Francis Herne

Fix crash when finding context inside annotated assigments.

The child nodes weren't visited by ContextBuilder or DeclarationBuilder,
 resulting in a crash if they contained an expression that tried to use
 currentContext().

BUG: 403045
FIXED-IN: 5.3.2
parent 5c552580
......@@ -1345,6 +1345,8 @@ void DeclarationBuilder::visitAssignment(AssignmentAst* node)
}
void DeclarationBuilder::visitAnnotationAssignment(AnnotationAssignmentAst* node) {
AstDefaultVisitor::visitAnnotationAssignment(node);
ExpressionVisitor v(currentContext());
v.visitNode(node->target);
v.visitNode(node->value);
......
......@@ -443,6 +443,10 @@ void PyDUChainTest::testCrashes_data() {
"def crash(): return f'expr={ {x: y for x, y in [(1, 2), ]}}'";
#endif
QTest::newRow("comprehension_in_lambda") << "lambda foo: [bar for bar in foo]";
QTest::newRow("comprehension_in_annassign_1") << "foo: int = [x for x in (42,)][0]";
QTest::newRow("comprehension_in_annassign_2") << "foo: [t for t in (int,)][0] = 42";
QTest::newRow("lambda_in_annassign_1") << "foo: int = (lambda: 42)()";
QTest::newRow("lambda_in_annassign_2") << "foo: (lambda: int)() = 42";
QTest::newRow("definition_in_baseclass_1") << "class Foo(lambda x: 1): pass";
QTest::newRow("definition_in_baseclass_2") << "class Foo([x for x in (1, 2)]): pass";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment