kdev-python: fix binary operators with unsure types
completed by: Levente Kurusa
mentors: Sven Brauch
kdev-python provides Python language support for the KDevelop IDE.
This is a difficult task -- it requires you to get somewhat familiar with KDevelop's duchain architecture and thus requires you to have firm C++ knowledge at least. But for the same reason, it might be very interesting ;) kdev-python does static analysis on python code. This means that it will try to guess types of objects without tracking control flow, and without actually executing code. In cases where no clear type can be determined, kdev-python will resort to e.g. unsure(int, string) if it can't tell if an object is an integer or a string. The problem this task aims to address is that currently, in code like class c: def __mul__(self, other): return int() x = c(); x = 3.5; y = 3 z = x * y z will be "mixed" instead of "unsure(int, float)" as it should be. The reason is that the analyzer does not support evaluating binary operators for unsure types.
To fix this, you want to look ExpressionVisitor::visitBinaryOperation and handle the case where v.lastType()->whichType() is TypeUnsure. In this case, the code should do what it does now for each type v.lastType() contains, and merge the resulting types in a new UnsureType, then return that.
Additionally, when no useful type can be determined from looking at the operator methods, it should just fall back to unsure(left operand, right operand). If you need help in working on this task (which I expect) feel free to contact me.