RFR: 8272135: jshell: Method cannot use its overloaded version

Vicente Romero vromero at openjdk.java.net
Wed Aug 18 17:36:37 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.

lgtm

-------------

Marked as reviewed by vromero (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5111


More information about the kulla-dev mailing list