Changeset 2307
- Timestamp:
- 03/10/10 08:30:47 (2 years ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 2 modified
-
Boxes.cobra (modified) (3 diffs)
-
Statements.cobra (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Boxes.cobra
r2305 r2307 285 285 body 286 286 if .genericDef is box, return this 287 for bt in .allBaseTypes 288 if bt.genericDef is box 289 return bt 287 for bt in .allBaseTypes, if bt.genericDef is box, return bt 290 288 return nil 291 289 … … 495 493 if this is .compiler.stringType # TODO: hacky. solution is to look at the specific type of .current property of enumerator. make a test case that shows that 496 494 return .compiler.charType 497 # can a for loop go through an IEnumerator<of>?495 # TODO: can a for loop go through an IEnumerator<of>? 498 496 # if .isConstructed and .genericDef is .compiler.enumeratorOfType 499 497 # return .genericParams[0] … … 831 829 return _genericDef is not nil 832 830 833 def isConstructionOf(box as Box) as bool 834 """ 835 Returns true if this type is a construction of the given generic type def, even going more than level deep through `genericDef`. 836 """ 837 # TODO: can this implementation be replaced by: 838 # return .constructedTypeOf(box) is not nil 839 if .genericDef is nil 840 return false 841 if .genericDef is box 842 return true 843 if .genericDef.genericDef 844 return .genericDef.isConstructionOf(box) # TODO: would iteration be more efficient here? 845 return false 831 def isDirectConstructionOf(box as Box) as bool 832 """ 833 Returns true if this type was directly constructed from the given box. 834 """ 835 require 836 .didBindInh 837 box.isGenericDef 838 body 839 return .genericDef is box 840 841 def isIndirectConstructionOf(box as Box) as bool 842 """ 843 Returns true if this type or any of its ancestor types 844 is a construction of the given generic type def. 845 """ 846 require 847 .didBindInh 848 box.isGenericDef 849 body 850 return .constructedTypeOf(box) is not nil 846 851 847 852 get isGenericDef as bool -
cobra/trunk/Source/Statements.cobra
r2300 r2307 591 591 isStreamOfKeyValue = .what.type.isDictionaryLike 592 592 if not isStreamOfKeyValue and _var.type inherits Box 593 isStreamOfKeyValue = (_var.type to Box).is ConstructionOf(.compiler.libraryType('System.Collections.Generic.KeyValuePair<of,>') to Box)593 isStreamOfKeyValue = (_var.type to Box).isIndirectConstructionOf(.compiler.libraryType('System.Collections.Generic.KeyValuePair<of,>') to Box) 594 594 if isStreamOfKeyValue 595 595 # This covers: … … 1462 1462 resultType = curCodeMember.resultType 1463 1463 if not resultType inherits StreamType and resultType <> .compiler.enumerableType and resultType <> .compiler.enumeratorType 1464 okay = false1464 bad = true 1465 1465 if resultType inherits Box 1466 1466 ienumerableOf = .compiler.enumerableOfType 1467 1467 ienumeratorOf = .compiler.enumeratorOfType 1468 okay = not (resultType is not ienumerableOf and resultType is not ienumeratorOf and not resultType.isConstructionOf(ienumerableOf) and not resultType.isConstructionOf(ienumeratorOf)) 1469 if not okay 1470 .throwError('Cannot yield unless the return type is an iterator type. Try "[expr.type.name]*".') 1468 bad = resultType is not ienumerableOf and resultType is not ienumeratorOf and not resultType.isDirectConstructionOf(ienumerableOf) and not resultType.isDirectConstructionOf(ienumeratorOf) 1469 if bad, .throwError('Cannot yield unless the return type is an iterator type. Try "[expr.type.name]*".') 1471 1470 if resultType inherits StreamType 1472 1471 elementType = resultType.innerType to !



