Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Follow up to GROOVY-9058. Consider the following:
List getSomeRows() { ... } @groovy.transform.CompileStatic void meth() { List<Object[]> rows = getSomeRows() rows.each { row -> def col = row[0] } }
The inferred type of rows is List and not List<Object[]> even though the assignment cleared type checking. This causes the inferred type of row to be Object instead of Object[].
Similarly, List<String> list = [] infers as ArrayList<String> instead of the explicit declared type, and Map<String, ?> map = [:] infers to LinkedHasMap<...> instead of the declared type. In general, I think as long as the assignment is compatible, the variable should retain its explicitly declared type regardless of assignments.
Attachments
Issue Links
- relates to
-
GROOVY-10914 Method ambiguity error even if the given argument has an explicit type
- Closed