mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python points-to: Be more specific when describing inheritance analysis failures.
This commit is contained in:
@@ -1826,31 +1826,38 @@ cached module Types {
|
||||
|
||||
/* Holds if type inference failed to compute the full class hierarchy for this class for the reason given. */
|
||||
cached predicate failedInference(ClassObjectInternal cls, string reason) {
|
||||
strictcount(cls.(PythonClassObjectInternal).getScope().getADecorator()) > 1 and reason = "Multiple decorators"
|
||||
exists(int priority |
|
||||
failedInference(cls, reason, priority) and
|
||||
priority = max(int p | failedInference(cls, _, p))
|
||||
)
|
||||
}
|
||||
|
||||
/* Holds if type inference failed to compute the full class hierarchy for this class for the reason given. */
|
||||
private predicate failedInference(ClassObjectInternal cls, string reason, int priority) {
|
||||
strictcount(cls.(PythonClassObjectInternal).getScope().getADecorator()) > 1 and reason = "Multiple decorators" and priority = 0
|
||||
or
|
||||
exists(cls.(PythonClassObjectInternal).getScope().getADecorator()) and not six_add_metaclass(_, cls, _) and reason = "Decorator not understood"
|
||||
exists(cls.(PythonClassObjectInternal).getScope().getADecorator()) and not six_add_metaclass(_, cls, _) and reason = "Decorator not understood" and priority = 1
|
||||
or
|
||||
reason = "Missing base " + missingBase(cls)
|
||||
reason = "Missing base " + missingBase(cls) and priority = 6
|
||||
or
|
||||
not exists(ObjectInternal meta | meta = cls.getClass() and not meta = ObjectInternal::unknownClass()) and reason = "Failed to infer metaclass"
|
||||
not exists(ObjectInternal meta | meta = cls.getClass() and not meta = ObjectInternal::unknownClass()) and reason = "Failed to infer metaclass" and priority = 4
|
||||
or
|
||||
exists(int i, ObjectInternal base1, ObjectInternal base2 |
|
||||
base1 = getBase(cls, i) and
|
||||
base2 = getBase(cls, i) and
|
||||
base1 != base2 and
|
||||
reason = "Multiple bases at position " + i
|
||||
)
|
||||
) and priority = 6
|
||||
or
|
||||
duplicateBase(cls) and reason = "Duplicate bases classes"
|
||||
duplicateBase(cls) and reason = "Duplicate bases classes" and priority = 6
|
||||
or
|
||||
not exists(getMro(cls)) and reason = "Failed to compute MRO" and not exists(missingBase(cls)) and not duplicateBase(cls)
|
||||
not exists(getMro(cls)) and reason = "Failed to compute MRO" and priority = 3
|
||||
or
|
||||
exists(int i | failedInference(getBase(cls, i), _) and reason = "Failed inference for base class at position " + i)
|
||||
exists(int i | failedInference(getBase(cls, i), _, _) and reason = "Failed inference for base class at position " + i) and priority = 5
|
||||
}
|
||||
|
||||
private int missingBase(ClassObjectInternal cls) {
|
||||
exists(cls.(PythonClassObjectInternal).getScope().getBase(result))
|
||||
and
|
||||
exists(cls.(PythonClassObjectInternal).getScope().getBase(result)) and
|
||||
not exists(ObjectInternal base | base = getBase(cls, result) and not base = ObjectInternal::unknownClass())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,14 @@
|
||||
| class A | Missing base 0 |
|
||||
| class B | Failed inference for base class at position 0 |
|
||||
| class B | Failed to compute MRO |
|
||||
| class C | Failed inference for base class at position 0 |
|
||||
| class C | Failed to compute MRO |
|
||||
| class D | Duplicate bases classes |
|
||||
| class E | Duplicate bases classes |
|
||||
| class E | Failed inference for base class at position 0 |
|
||||
| class E | Failed inference for base class at position 1 |
|
||||
| class E | Failed inference for base class at position 2 |
|
||||
| class E | Failed inference for base class at position 3 |
|
||||
| class E | Failed inference for base class at position 4 |
|
||||
| class E | Failed inference for base class at position 5 |
|
||||
| class E | Failed inference for base class at position 6 |
|
||||
| class E | Failed inference for base class at position 7 |
|
||||
| class E | Failed inference for base class at position 8 |
|
||||
| class E | Failed inference for base class at position 9 |
|
||||
| class E | Failed inference for base class at position 10 |
|
||||
| class G | Failed inference for base class at position 0 |
|
||||
| class G | Failed to compute MRO |
|
||||
| class H | Failed inference for base class at position 0 |
|
||||
| class H | Failed to compute MRO |
|
||||
| class J | Missing base 0 |
|
||||
| class L | Failed inference for base class at position 0 |
|
||||
| class L | Failed to compute MRO |
|
||||
| class M | Failed inference for base class at position 0 |
|
||||
| class M | Failed to compute MRO |
|
||||
| class N | Failed inference for base class at position 0 |
|
||||
| class N | Failed to compute MRO |
|
||||
| class R | Failed inference for base class at position 0 |
|
||||
| class R | Failed to compute MRO |
|
||||
| class S | Failed inference for base class at position 0 |
|
||||
| class S | Failed to compute MRO |
|
||||
| class T | Failed inference for base class at position 0 |
|
||||
| class T | Failed to compute MRO |
|
||||
|
||||
Reference in New Issue
Block a user