Forums

Should this be an error

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Should this be an error

Postby hopscc » Mon Jul 27, 2009 1:18 am

From Question in ticket:170
Code: Select all
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
Code: Select all
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

from ( l is a List<Of Object>) and so become x and y

Should it ??
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Should this be an error

Postby Charles » Mon Jul 27, 2009 2:12 am

Currently, a list of heterogeneous types such as [true, 3] will yield an inferred type of List<of Object>, but I've been thinking for awhile that 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 your example would work and Cobra would gain another bit of that good ol' Python convenience.

This would apply to inference on set and dictionary literals as well.

I would certainly accept a patch for this. Or I'll get to it eventually if no one beats me to it.

Thanks for bringing this up. I didn't see what the problem was at first when you mentioned it and then it slipped my mind.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 51 guests