eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Full qualified class names for tooltips when class names are the same regardless of generics
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
### Problem
Consider the following example:
```
package mwe;
public class C {}
```
```
package otherpkg;
public class C {}
```
```
package mwe;
public class UnqualifiedHints {
void f1(mwe.C c) { f2(c); }
void f2(otherpkg.C c) {}
void g1(mwe.C c) { g2(c); }
void g2(otherpkg.C c) {}
}
```
Compiler warns on both calls to `f2` and `g2` that the classes don't match. To accomodate the fact that both classes have the same name to distinguish the tooltip on `g2` shows
```
The method g2(otherpkg.C) in the type UnqualifiedHints is not applicable for the arguments (mwe.C)
```
However because the generics in `f2` are "different", these are seen as two different types and so the unhelpful tooltip
```
The method f2(C) in the type UnqualifiedHints is not applicable for the arguments (C)
```
appears, leading to the assumption (at least by me and my colleagues) that something is wrong with the generics.
### Possible solution
Ignore generics when determining if a class name has to be written out full qualified to solve ambiguities.
### additional information
`javac 18` writes out the full qualified class names in both cases:
```
mwe\UnqualifiedHints.java:3: error: method f2 in class UnqualifiedHints cannot be applied to given types;
void f1(mwe.C c) { f2(c); }
^
required: otherpkg.C
found: mwe.C
reason: cannot infer type-variable(s) M
(argument mismatch; mwe.C cannot be converted to otherpkg.C)
where M,T are type-variables:
M extends Object declared in method f2(otherpkg.C)
T extends Object declared in method f1(mwe.C)
mwe\UnqualifiedHints.java:6: error: method g2 in class UnqualifiedHints cannot be applied to given types;
void g1(mwe.C c) { g2(c); }
^
required: otherpkg.C
found: mwe.C
reason: cannot infer type-variable(s) T#1
(argument mismatch; mwe.C cannot be converted to otherpkg.C)
where T#1,T#2 are type-variables:
T#1 extends Object declared in method g2(otherpkg.C)
T#2 extends Object declared in method g1(mwe.C)
2 errors
```
`ecj 3.29.0` also writes full qualified class names:
```
mwe\UnqualifiedHints.java:[6,3] The method f2(otherpkg.C) in the type mwe.UnqualifiedHints is not applicable for the arguments (mwe.C)
mwe\UnqualifiedHints.java:[12,3] The method g2(otherpkg.C) in the type mwe.UnqualifiedHints is not applicable for the arguments (mwe.C)
```
Tested with
Eclipse SDK
Version: 2022-06 (4.25)
Build id: I20220612-1800
openjdk version "18" 2022-03-22
OpenJDK Runtime Environment Temurin-18+36 (build 18+36)
OpenJDK 64-Bit Server VM Temurin-18+36 (build 18+36, mixed mode, sharing)
org.eclipse.jdt:ecj:3.29.0
Contributor guide
Assessment
This issue has not been assessed yet.