Integrated: 8282160: JShell circularly-required classes cannot be defined

Jan Lahoda jlahoda at openjdk.java.net
Fri May 13 09:49:49 UTC 2022


On Mon, 28 Feb 2022 16:08:29 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider JShell snippets like:
> 
> jshell> class B {
>             C c;
>             public void run() {
>             }
>         }
> jshell> class C extends B {
>             public void run() {
>             }
>         }
> 
> 
> When the first snippet is processed, it cannot be fully compiled, because `C` is missing. When the second snippet is processed, it is first processed separately, but it will turn out it needs `B` to be defined, and that there are no errors in `C` except resolution errors, and JShell will process both the snippets together, which will pass.
> 
> If the second snippet is changed to:
> 
> jshell> class C extends B {
>             @Override
>             public void run() {
>             }
>         }
> 
> 
> then when processing `C`, there will be error: "method does not override or implement a method from a supertype" (in addition to the "`B` does not exist"). But that error is not considered a resolution error by JShell.
> 
> The proposal here is to ignore the "does not override" errors and join the `C` and `B` snippet processing. An alternative would be to not produce the error when there are erroneous supertypes, but that turns out to be tricky when the error is not in the direct supertype. So the proposal is to tweak JShell for now.

This pull request has now been integrated.

Changeset: 11fa03f3
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/11fa03f3ee0e0224a14f6bcf88cdd92e17ed0784
Stats:     34 lines in 3 files changed: 28 ins; 0 del; 6 mod

8282160: JShell circularly-required classes cannot be defined

Reviewed-by: vromero

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

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


More information about the kulla-dev mailing list