Merge pull request #3243 from BekaValentine/python-objectapi-to-valueapi-incorrectlyspecifiedoverriddenmethod

Python: ObjectAPI to ValueAPI: IncorrectlySpecifiedOverriddenMethod
This commit is contained in:
Taus
2020-04-14 18:55:42 +02:00
committed by GitHub
3 changed files with 39 additions and 15 deletions

View File

@@ -13,21 +13,21 @@
import python
import Expressions.CallArgs
from Call call, FunctionObject func, FunctionObject overriding, string problem
from Call call, FunctionValue func, FunctionValue overriding, string problem
where
not func.getName() = "__init__" and
overriding.overrides(func) and
call = overriding.getAMethodCall().getNode() and
correct_args_if_called_as_method_objectapi(call, overriding) and
correct_args_if_called_as_method(call, overriding) and
(
arg_count_objectapi(call) + 1 < func.minParameters() and problem = "too few arguments"
arg_count(call) + 1 < func.minParameters() and problem = "too few arguments"
or
arg_count_objectapi(call) >= func.maxParameters() and problem = "too many arguments"
arg_count(call) >= func.maxParameters() and problem = "too many arguments"
or
exists(string name |
call.getAKeyword().getArg() = name and
overriding.getFunction().getAnArg().(Name).getId() = name and
not func.getFunction().getAnArg().(Name).getId() = name and
overriding.getScope().getAnArg().(Name).getId() = name and
not func.getScope().getAnArg().(Name).getId() = name and
problem = "an argument named '" + name + "'"
)
)

View File

@@ -573,6 +573,9 @@ class ClassValue extends Value {
abstract class FunctionValue extends CallableValue {
abstract string getQualifiedName();
/** Gets a longer, more descriptive version of toString() */
abstract string descriptiveString();
/** Gets the minimum number of parameters that can be correctly passed to this function */
abstract int minParameters();
@@ -605,6 +608,14 @@ abstract class FunctionValue extends CallableValue {
)
}
/** Gets a call-site from where this function is called as a method */
CallNode getAMethodCall() {
exists(BoundMethodObjectInternal bm |
result.getFunction().pointsTo() = bm and
bm.getFunction() = this
)
}
/** Gets a class that this function may return */
abstract ClassValue getAnInferredReturnType();
}
@@ -617,6 +628,15 @@ class PythonFunctionValue extends FunctionValue {
result = this.(PythonFunctionObjectInternal).getScope().getQualifiedName()
}
override string descriptiveString() {
if this.getScope().isMethod()
then
exists(Class cls | this.getScope().getScope() = cls |
result = "method " + this.getQualifiedName()
)
else result = "function " + this.getQualifiedName()
}
override int minParameters() {
exists(Function f |
f = this.getScope() and
@@ -650,6 +670,8 @@ class BuiltinFunctionValue extends FunctionValue {
override string getQualifiedName() { result = this.(BuiltinFunctionObjectInternal).getName() }
override string descriptiveString() { result = "builtin-function " + this.getName() }
override int minParameters() { none() }
override int maxParameters() { none() }
@@ -674,6 +696,8 @@ class BuiltinMethodValue extends FunctionValue {
)
}
override string descriptiveString() { result = "builtin-method " + this.getQualifiedName() }
override int minParameters() { none() }
override int maxParameters() { none() }