Integrated: 8272135: jshell: Method cannot use its overloaded version
Jan Lahoda
jlahoda at openjdk.java.net
Tue Sep 7 09:53:41 UTC 2021
On Fri, 13 Aug 2021 15:20:10 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: 70157c78
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/70157c78a838126bb29c91a410d9158763bfa2ad
Stats: 108 lines in 4 files changed: 89 ins; 0 del; 19 mod
8272135: jshell: Method cannot use its overloaded version
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/5111
More information about the kulla-dev
mailing list