New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Find uses" has false positives when a function is overridden in a class hierarchy #19697
Comments
Added this to the 1.6 milestone. |
Removed this from the 1.6 milestone. |
Set owner to @scheglov. |
Removed Oldschool-Milestone-1.6 label. |
Paul, Brian, could you please review the following test code and see if it satisfies your expectations about search results? test_method_whenExtends() { test_method_whenImplements() { cc @bwilkerson. |
I'm troubled by the "whenExtends" test code because not only do all the called methods have the same name (mmm), but all the calling methods have the same name as well (use_mmm). This means that in principle, once could make even tighter inferences about what's callable than what I've requested in this bug report (for example, even B.use_mmm can't call C.use_mmm, because the only way B.use_mmm could be called on an object derived from C is via a super call, and there are no super calls in this code). I'd feel much more comfortable if we gave all the use_mmm calls different names (as I did in the bug report). However even with that change I believe some of the test code is incorrect. See my note (marked "(*)") below: test_method_whenExtends() { assertHasResult(SearchResultKind.INVOCATION, 'mmm(2)'); test_method_whenImplements() seems correct to me. |
Partial (very partial) fix. Added Started label. |
Rollback of the previous CL |
OK, there are (probably) use case for this, but I'm not going to land it now. Attachment: Removed the owner. |
Consider the following code:
class Base {
f() {}
methodInBase() {
f();
}
}
class Derived1 extends Base {
f() {}
methodInDerived1() {
f();
}
}
class Derived2 extends Base {
methodInDerived2() {
f();
}
}
functionTakingBase(Base b) {
b.f();
}
functionTakingDerived1(Derived1 d1) {
d1.f();
}
functionTakingDerived2(Derived2 d2) {
d2.f();
}
A search for uses of Base.f() or Derived1.f() returns all 6 invocations of f(). However some of these invocations are false positives:
By similar arguments, a search for uses of Base.f() should not return functionTakingDerived1(), and a search for uses of Derived1.f() should not return functionTakingDerived2(). These arguments are less airtight, since in unchecked mode it's possible for any type to be passed to any function. However I would argue that these unchecked uses violate programmer intent and so they're very unlikely what the user is seeking.
The text was updated successfully, but these errors were encountered: