Skip to content

Commit 65627f8

Browse files
Include conditional alert messages for various cases
1 parent 2e0f4b8 commit 65627f8

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

python/ql/src/Functions/SignatureOverriddenMethod.ql

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import python
1616
import semmle.python.dataflow.new.DataFlow
1717
import semmle.python.dataflow.new.internal.DataFlowDispatch
18+
import codeql.util.Option
1819

1920
predicate overrides(Function base, Function sub) {
2021
base.getName() = sub.getName() and
@@ -54,7 +55,7 @@ predicate weakSignatureMismatch(Function base, Function sub, string msg) {
5455
msg =
5556
"requires " +
5657
plural(sub.getMinPositionalArguments() - base.getMinPositionalArguments(),
57-
"more positional argument") + "than some possible calls to overridden $@."
58+
"more positional argument") + " than some possible calls to overridden $@."
5859
or
5960
sub.getMaxPositionalArguments() < base.getMaxPositionalArguments() and
6061
msg =
@@ -173,16 +174,28 @@ Call chooseASignatureMismatchWitness(Function base, Function sub) {
173174
)
174175
}
175176

176-
from Function base, Function sub, string msg, string extraMsg, Call call
177+
module CallOption = LocOption2<Location, Call>;
178+
179+
from Function base, Function sub, string msg, string extraMsg, CallOption::Option call
177180
where
178181
not sub.isSpecialMethod() and
179182
sub.getName() != "__init__" and
180183
not ignore(sub) and
181184
not ignore(base) and
182185
matchingStatic(base, sub) and
183-
weakSignatureMismatch(base, sub, msg) and
184-
//msg = " has a different signature to $@." and
185-
call = chooseASignatureMismatchWitness(base, sub) and
186-
extraMsg =
187-
" $@ correctly calls the base method, but does not match the signature of the overriding method."
186+
(
187+
call.asSome() = chooseASignatureMismatchWitness(base, sub) and
188+
extraMsg =
189+
" $@ correctly calls the base method, but does not match the signature of the overriding method." and
190+
(
191+
strongSignatureMismatch(base, sub, msg)
192+
or
193+
not strongSignatureMismatch(base, sub, _) and
194+
weakSignatureMismatch(base, sub, msg)
195+
)
196+
or
197+
not exists(getASignatureMismatchWitness(base, sub)) and
198+
strongSignatureMismatch(base, sub, msg) and
199+
extraMsg = ""
200+
)
188201
select sub, "This method " + msg + extraMsg, base, base.getQualifiedName(), call, "This call"

0 commit comments

Comments
 (0)