Page 1 of 1

Should this be an error

PostPosted: Mon Jul 27, 2009 1:18 am
by hopscc
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 ??

Re: Should this be an error

PostPosted: Mon Jul 27, 2009 2:12 am
by Charles
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.