[python] Fix NPE in PyAstAsPattern

(cherry picked from commit d8f319769d8fd25c27e6ab75b05d94d56a9751b9)

IJ-CR-172556

GitOrigin-RevId: c0c921a2ef363c9e3b33a21869cc290896372ab6
This commit is contained in:
Aleksandr.Govenko
2025-06-27 18:42:21 +02:00
committed by intellij-monorepo-bot
parent adcc559e5c
commit 31dcf9f6d5
2 changed files with 5 additions and 3 deletions

View File

@@ -8,8 +8,8 @@ interface PyAstAsPattern : PyAstPattern {
return requireNotNull(findChildByClass(PyAstPattern::class.java)) { "${this}: pattern cannot be null" }
}
fun getTarget(): PyAstTargetExpression {
return requireNotNull(findChildByClass(PyAstTargetExpression::class.java)) { "${this}: target cannot be null" }
fun getTarget(): PyAstTargetExpression? {
return findChildByClass(PyAstTargetExpression::class.java)
}
override fun isIrrefutable(): Boolean {

View File

@@ -457,7 +457,9 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
// So no need to create an additional fail edge
myBuilder.startNode(node);
node.acceptChildren(this);
myPatternBindingNames.add(node.getTarget().getName());
if (node.getTarget() != null) {
myPatternBindingNames.add(node.getTarget().getName());
}
myBuilder.updatePendingElementScope(node, node.getParent());
}