Commit 1fed938f authored by Sven Brauch's avatar Sven Brauch
Browse files

Fix negative tuple indices from crashing the parser.

BUG:304993
parent 18d0db71
......@@ -445,7 +445,10 @@ void ExpressionVisitor::visitSubscript(SubscriptAst* node)
if ( sliceIndexAst->value && sliceIndexAst->value->astType == Ast::NumberAstType ) {
NumberAst* number = static_cast<NumberAst*>(sliceIndexAst->value);
int sliceIndex = number->value;
if ( sliceIndex < indexed->typesCount() ) {
if ( sliceIndex < 0 && sliceIndex + indexed->typesCount() > 0 ) {
sliceIndex += indexed->typesCount();
}
if ( sliceIndex < indexed->typesCount() && sliceIndex >= 0 ) {
return encounter(indexed->typeAt(sliceIndex).abstractType());
}
}
......
......@@ -145,6 +145,7 @@ void PyDUChainTest::testCrashes_data() {
QTest::addColumn<QString>("code");
QTest::newRow("unicode escape char") << "print u\"\\xe9\"";
QTest::newRow("negative slice index") << "t = (1, 2, 3)\nd = t[-1]";
QTest::newRow("fancy generator context range") << "c1_list = sorted(letter for (letter, meanings) \\\n"
"in ambiguous_nucleotide_values.iteritems() \\\n"
"if set([codon[0] for codon in codons]).issuperset(set(meanings)))";
......
Supports Markdown
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