Wiki

Ticket #176 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

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

lit-collections-dynamic.patch Download (5.8 KB) - added by hopscc 8 years ago.

Change History

Changed 8 years ago by Chuck

  • milestone set to Cobra 0.9

Changed 8 years ago by Chuck

I think the correct Summary would be:

"Heterogeneous collection literals are inferred as <of Object> instead of <of dynamic>"

Changed 8 years ago by hopscc

  • status changed from new to assigned
  • owner set to hopscc

Changed 8 years ago by hopscc

  • summary changed from Assignment does not infer types of expressions from a generic List/Set/Dict Literal to Heterogeneous collection literals are inferred as <of Object> instead of <of dynamic>

Changed 8 years ago by hopscc

Changed 8 years ago by hopscc

  • owner changed from hopscc to Chuck

patch, new tests, fix now assignment failure lit list to Object*,
relnote.

Changed 8 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to fixed

Thanks. Applied in changeset:2250

Note: See TracTickets for help on using tickets.