Ticket #162: array-coVar.patch
File array-coVar.patch, 3.9 KB (added by hopscc, 15 years ago) |
---|
-
Source/Types.cobra
1665 1665 if type inherits ArrayType 1666 1666 if _wrappedType == type.theWrappedType 1667 1667 return true 1668 # arrays assignable to arrays if element assignable (covariance) 1669 if _wrappedType.isAssignableTo( type.theWrappedType) 1670 return true 1668 1671 if type inherits StreamType 1669 return .isAssignableTo(type.box to !) 1672 #trace 'array assignable to streamType' 1673 if .isAssignableTo(type.box to !) 1674 return true 1675 # arrays being IEnumerable assignable to stream/IEnumerable if element assignable 1676 if _wrappedType.isAssignableTo( type.innerType to !) 1677 return true 1670 1678 return false 1671 1679 1672 1680 def _bindInh -
Source/Container.cobra
247 247 return true 248 248 if type inherits NilableType 249 249 return .isAssignableTo(type.theWrappedType to passthrough) # CC: weird cast. bug. has to do with if-inherits and invoking the same method 250 result _ = .isDescendantOf(type) # CC: rename to result251 return result _250 result = .isDescendantOf(type) 251 return result 252 252 253 253 # CC: duplicated from Type 254 254 def isComparableTo(t as IType) as bool -
Tests/820-errors/600-other/140-coVariance-not.cobra
1 # Assignment from an array (to stream and array) for Types that are unrelated - expected to fail compilation 2 class CoVar 3 shared 4 var foo2 as IFoo* 5 6 var afoo2 as IFoo[] 7 8 def main 9 #array to stream covariance - - except they are unrelated 10 CoVar.foo2 = @[BarNoFoo(), BarNoFoo()] # .error. cannot assign value of type BarNoFoo[] on the right to IFoo* on the left 11 12 # array to array covariance - except they are unrelated 13 CoVar.afoo2 = @[BarNoFoo(), BarNoFoo()] # .error. Cannot assign value of type BarNoFoo[] on the right to IFoo[] on the left 14 15 16 interface IFoo 17 pass 18 19 class Bar 20 implements IFoo 21 pass 22 23 interface INoFoo 24 pass 25 26 class BarNoFoo 27 implements INoFoo 28 pass 29 -
Tests/200-misc/830-coVariance-from-array.cobra
1 # Assignment from an array (to stream and array) for element Types that are related 2 # 3 class CoVar 4 shared 5 var fooSingleNil as IFoo? 6 var foo as IFoo* 7 var fooNil as IFoo*? 8 9 var afoo as IFoo[] 10 var afooNil as IFoo[]? 11 12 def main 13 CoVar.fooSingleNil = Bar() 14 15 #array to stream covariance 16 CoVar.foo = @[Bar(), Bar()] 17 CoVar.fooNil = @[Bar(), Bar()] 18 19 # array to array covariance 20 CoVar.afoo = @[Bar(), Bar()] 21 CoVar.afooNil = @[Bar(), Bar()] 22 23 # should stream to stream also be allowed? 24 #CoVar.foo = [Bar(), Bar()] 25 26 27 28 interface IFoo 29 pass 30 31 class Bar 32 implements IFoo 33 pass 34 35 -
Developer/IntermediateReleaseNotes.text
42 42 def foo(p as Type has Attribute(args)) # attribute applies to parameter 43 43 has return Attribute(args) # attribute applies to return value due to `return` keyword 44 44 45 * Support array coVariance from arrays to arrays and streams ticket:162 45 46 46 47 ================================================================================ 47 48 Library