Commit 172dc513 authored by Francis Herne's avatar Francis Herne
Browse files

Fix ExtSlice crash with Python <= 3.8

BUG: 426292
FIXED-IN: 5.6.1

The dimensions of an ExtSlice node are _slice nodes rather than _expr,
 so this would crash whenever encountering one.

 --

This was introduced in commit 05e95cac "Initial support for CPython 3.9".

When I replaced `SliceAst` with `ExpressionAst` in the relevant line
 of python39.sdef, conversionGenerator.py *also* changed `_slice` to `_expr` here
 (because the type used is implicitly determined in a stupid way)
 and I failed to notice that difference in the newly-generated code.

I couldn't see an easy way to fix the implicit type thing, so this commit just
 bypasses that mechanism and uses CODE instead.
parent 93e2e103
......@@ -255,6 +255,7 @@ void PyDUChainTest::testCrashes() {
void PyDUChainTest::testCrashes_data() {
QTest::addColumn<QString>("code");
QTest::newRow("composite_slice") << "A = M[1:3, 3]";
QTest::newRow("unicode_char") << "a = \"í\"";
QTest::newRow("unicode escape char") << "print(\"\\xe9\")";
QTest::newRow("augassign") << "a = 3\na += 5";
......
......@@ -510,7 +510,7 @@ PyObject *value = node->v.Constant.value;if (value == Py_None) { NameConstant
#if PYTHON_VERSION < QT_VERSION_CHECK(3, 9, 0)
case ExtSlice_kind: {
TupleAst* v = new TupleAst(parent());
nodeStack.push(v); v->elements = visitNodeList<_expr, ExpressionAst>(node->v.ExtSlice.dims); nodeStack.pop();
nodeStack.push(v); v->elements = visitNodeList<_slice, ExpressionAst>(node->v.ExtSlice.dims); nodeStack.pop();
result = v;
break;
}
......
......@@ -132,7 +132,8 @@ RULE_FOR _expr;KIND NamedExpr_kind;ACTIONS create|AssignmentExpressionAst set|ta
RULE_FOR _expr;KIND Slice_kind;ACTIONS create|SliceAst set|lower->ExpressionAst,lower set|upper->ExpressionAst,upper set|step->ExpressionAst,step;SINCE 3.9;;
RULE_FOR _slice;KIND Slice_kind;ACTIONS create|SliceAst set|lower->ExpressionAst,lower set|upper->ExpressionAst,upper set|step->ExpressionAst,step;BEFORE 3.9;;
RULE_FOR _slice;KIND ExtSlice_kind;ACTIONS create|TupleAst set|elements=>ExpressionAst,dims;BEFORE 3.9;;
RULE_FOR _slice;KIND ExtSlice_kind;ACTIONS create|TupleAst;BEFORE 3.9;CODE
nodeStack.push(v); v->elements = visitNodeList<_slice, ExpressionAst>(node->v.ExtSlice.dims); nodeStack.pop();;
RULE_FOR _slice;KIND Index_kind;ACTIONS;BEFORE 3.9;CODE return visitNode(node->v.Index.value);;
......
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