Changeset 2305
- Timestamp:
- 03/10/10 06:47:00 (2 years ago)
- Location:
- cobra/trunk
- Files:
-
- 3 modified
-
Source/Boxes.cobra (modified) (2 diffs)
-
Source/NameSpace.cobra (modified) (1 diff)
-
Tests/420-extensions/400-extend-generics/220-extend-ancestor-interface.cobra (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Boxes.cobra
r2299 r2305 835 835 Returns true if this type is a construction of the given generic type def, even going more than level deep through `genericDef`. 836 836 """ 837 # TODO: can this implementation be replaced by: 838 # return .constructedTypeOf(box) is not nil 837 839 if .genericDef is nil 838 840 return false … … 1764 1766 if box.isDescendantOf(cto) and .declForName(name) 1765 1767 return .constructedTypeFor(cto.genericParams).declForName(name) 1768 else if .isGeneric 1769 # Example: 1770 # this == Extension of IEnumerable<of T> 1771 # box == X implements IEnumerable<of int> 1772 # name == 'toList' 1773 # The IEnumerable<of T> has .genericDef IEnumerable<> 1774 # The X's IEnumerable<of int> has .genericDef IEnumerable<> 1775 # Note that X and the Extension are not directly connected. 1776 # Only by tracing up to the generic def IEnumerable<> do they "connect". 1777 # see cobra/Tests/420-extensions/400-extend-generics/220-extend-ancestor-interface.cobra 1778 constructed = box.constructedTypeOf(_extendedBox.genericDef to !) 1779 if constructed, return .extensionMemberFor(constructed, name) 1766 1780 return nil 1767 1781 1768 1782 def memberForName(name as String) as IMember? 1769 1783 result = base.memberForName(name) 1770 if result is nil 1771 result = .extendedBox.memberForName(name) 1784 if result is nil, result = .extendedBox.memberForName(name) 1772 1785 return result 1773 1786 -
cobra/trunk/Source/NameSpace.cobra
r2299 r2305 1 interface INameSpaceMember 2 inherits IMember, ISyntaxNode 1 interface INameSpaceMember inherits IMember, ISyntaxNode 3 2 """ 4 3 Anything that can be a member of a namespace should implement INameSpaceMember. -
cobra/trunk/Tests/420-extensions/400-extend-generics/220-extend-ancestor-interface.cobra
r2240 r2305 1 # Invoke a method in an extension of a generic, ancestor interface.2 # In this case, the class is Dictionary<of TKey, TValue>.KeyCollection3 # and the extension method is declared on IEnumerable<of TKey> which KeyCollection implements.4 5 # Then do it again for Dictionary<of TKey, TValue>.ValueCollection6 # Note that it implement IEnumerable<of TValue> which is using the *2nd* generic parameter, not the first.7 8 1 class Test 9 2 10 3 def main 4 .test1 5 .test2 6 7 def test1 8 # Invoke a method in an extension of a generic, ancestor interface. 9 # In this case, the class is Dictionary<of TKey, TValue>.KeyCollection 10 # and the extension method is declared on IEnumerable<of TKey> which KeyCollection implements. 11 12 # Then do it again for Dictionary<of TKey, TValue>.ValueCollection 13 # Note that it implement IEnumerable<of TValue> which is using the *2nd* generic parameter, not the first. 11 14 d = {'x': 1, 'y': 1} 12 15 … … 18 21 assert value == 1 19 22 assert (for value in d.values.toList get value) == [1, 1] 23 24 def test2 25 x = X() 26 .takeEnum(x) 27 y = x.toList # previously broken. Cobra would not find the extension method. 28 assert y == List<of int>(x) 29 assert y == [1, 2, 3] 30 31 def takeEnum(e as IEnumerable<of int>) 32 assert e.toList is not e 33 assert e.toList == List<of int>(e) 34 35 36 class X implements IEnumerable<of int> 37 38 def getEnumerator as IEnumerator<of int> 39 return [1, 2, 3].getEnumerator 40 41 def getEnumerator as System.Collections.IEnumerator 42 implements System.Collections.IEnumerable 43 return .getEnumerator



