Ticket #176 (closed defect: fixed)
Heterogeneous collection literals are inferred as <of Object> instead of <of dynamic>
Reported by: | hopscc | Owned by: | Chuck |
---|---|---|---|
Priority: | major | Milestone: | Cobra 0.9 |
Component: | Cobra Compiler | Version: | 0.8.0 |
Keywords: | Cc: |
Description
Follow up from ticket:170 and Forum Topic Should This be an error
class X def main a = 'aoeu' to Object b = 5 to Object l = [a to String, b to int] x = l[0] y = l[1] assert x.length == 4 assert y * 2 == 10
Fails with
castInList.cobra(8): error: Cannot find a definition for "length" in "x" whose type is "Object". castInList.cobra(9): error: Cannot apply STAR to Object and int. Try finding a method that performs this function. Compilation failed - 2 errors, 0 warnings
Currently, a list of heterogeneous types such as [true, 3] will yield an inferred type of List<of Object>, but unless the actual element types are all Object (or Object?), the inferred type should be List<of dynamic> instead. If that were the case, then the above would work and Cobra would gain another bit of that good ol' Python convenience.
This should apply to inference on set and dictionary literals as well.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.