RFR: 8316470: Incorrect error location for "invalid permits clause" depending on file order

Aggelos Biboudis abimpoudis at openjdk.org
Wed Oct 18 10:18:16 UTC 2023


On Tue, 17 Oct 2023 15:10:19 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider code like (in two different files, but accessible through source path):
> 
> class Main extends C {}
> 
> 
> sealed class C {} //does not permit Main
> 
> 
> and a javac process that will start attribution with `Main`. As part of `Main` attribution, its superclasses will be attributed, hence `C` will be attributed. And there will be a sealing error reported for `C` (missing permitted). But, the source in the logger will still be set to `Main`, and hence the report will be reported at a weird place in `Main`, not in `C`.
> 
> The proposed solution is simple: move the code to set the source to logger (and related code) before the sealed checks. The diff looks scary, but it is movement of several lines up, and whitespace changes.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 5422:

> 5420:             ResultInfo prevReturnRes = env.info.returnResult;
> 5421: 
> 5422:             try {

Previously this `try` block didn't include this code. Is, the new position of `try`, intentional?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16221#discussion_r1363617182


More information about the compiler-dev mailing list