RFR: 8272135: jshell: Method cannot use its overloaded version
Jan Lahoda
jlahoda at openjdk.java.net
Fri Aug 13 15:26:43 UTC 2021
Consider separate snippets like:
int m(int i) { return 1; }
and:
int m(String s) { return m(0); }
If these are independent snippets, JShell will currently compile first the first snippet (say into class called `A`), and then the second snippet. The actual code for the second snippet will be in this direction:
import static A.m;
public class B {
int m(String s) { return m(0); }
}
Note that here the method resolution, when seeing method name `m`, will not see the `m(int)` method at all, as the lookup will stop on the current class' method called `m` and will never proceed to look at the `m` method from the first snippet/class `A`.
JShell generally tries to coalescence processing of overloading methods (in the `Unit.setWrap` method), but the overloaded methods must be together part of the input, which is not the case in the above example.
The proposed solution is to detect the possibility of the above situation (call of a method that has the same name as the current snippet's method), and add all same-named overloads to the processing set.
-------------
Commit messages:
- 8272135: jshell: Method cannot use its overloaded version
Changes: https://git.openjdk.java.net/jdk/pull/5111/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=5111&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8272135
Stats: 108 lines in 4 files changed: 89 ins; 0 del; 19 mod
Patch: https://git.openjdk.java.net/jdk/pull/5111.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/5111/head:pull/5111
PR: https://git.openjdk.java.net/jdk/pull/5111
More information about the kulla-dev
mailing list