eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Unresolvable type when class with the same name is nested in a record

Open
#2,862 0 comments 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
49

Description

Consider a project `test-b` containing one file, `B.java`:
```
package test;

public class B {}
```

Consider another project, `test-a`, containing two files, `Main.java`:
```
package test;

public class Main {
public static void main(String[] args) {
B b = new B();
}
}
```
and `A.java`:
```
package test;

public class A {
public class B {}
}
```

`test-b` is referenced in the classpath of `test-a`, and consequently the `main` method compiles happily with `B b` resolving to the class defined in `test-b/B.java`.

However, if I switch class A to be a record as follows, things break down:
```
package test;

public record A() {
public class B {
}
}
```

* the main method no longer compiles, claiming that `B cannot be resolved to a type`.
* Eclipse suggests to `Import 'B' (test)` when triggering quickfixes on the `B b = new B()` declaration, but this has no effect (as B should already have package visibility).
* Going to declarations opens record `A`.
* If I modify the Order and Export settings so that `test-b` comes before `test-a/src` in the Java build path, then things fall back into place. Same if I rename the inner class `test-a/A.B` to `test-a/A.C`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.