Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.4.5
-
None
-
None
Description
While reading the test case for GROOVY-5839, I noticed it did not actually match the reported problem, which is about a method-level generic type shadowing a class-level generic type. However, the real problem is that the code compiles even without the shadowing of the generic type of the class by the method:
class GoodCodeRed<T> { Collection<GoodCodeRed<T>> attached = [] public <U> void attach(GoodCodeRed<U> toAttach) { attached.add(toAttach) } } def g1 = new GoodCodeRed<Integer>() def g2 = new GoodCodeRed<Integer>() g1.attach(g2)
T and U are unrelated, the attached.add(toAttach) call should not compile.
Once that is fixed, we can see if the shadowing of the type is also an issue, simply by renaming U to T.
Attachments
Issue Links
- is related to
-
GROOVY-5839 Typechecker does not detect shadowed generic parameter
- Closed
- relates to
-
GROOVY-7720 Type incompatibility of generic placeholders not detected on assignment
- Reopened