Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.5
-
None
-
None
Description
I want to provoke a compiler error. I am omitting the type parameter of a generic List and use it as a raw type. When getting an object from the raw list it should be of type Object. When casting this Object implicitly to an Integer the compiler should throw an illegal assignment error but it doesn't.
The following code example should illustrate the problem. Case 2 and 3 should throw the same error but only case 3 is producing an error.
import groovy.transform.TypeChecked @TypeChecked class Test { static method() { ArrayList<Integer> integerArrayList = new ArrayList<>(); ArrayList rawArrayList = new ArrayList(); ArrayList<Object> objectArrayList = new ArrayList<>(); integerArrayList << 1; rawArrayList << new Object(); objectArrayList << new Object(); Integer x = integerArrayList.get(0); // Case 1: works as expected Integer y = rawArrayList.get(0); // Case 2: doesn't throw a compile error but should Integer z = objectArrayList.get(0); // Case 3: throws a compile error as expected } }
Attachments
Issue Links
- is fixed by
-
GROOVY-10055 STC does not support self bounded types
- Closed