Changeset 2310
- Timestamp:
- 03/11/10 09:47:16 (2 years ago)
- Location:
- cobra/trunk
- Files:
-
- 1 added
- 4 modified
-
Source/BinaryOpExpr.cobra (modified) (1 diff)
-
Source/Members.cobra (modified) (2 diffs)
-
Source/Types.cobra (modified) (9 diffs)
-
Tests/110-basics-two/800-arrays/200-array-interfaces.cobra (added)
-
Tests/700-command-line/112-run-hello.cobra (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/BinaryOpExpr.cobra
r2304 r2310 782 782 else if not _canContain(.right.type to !, .left.type to !) 783 783 .recordError('The left expression ([.left.toCobraSource]) cannot be "in" the right-hand expression because the left type is "[.left.type.name]" and the right-hand expression contains type "[.right.type.innerType.name]".') 784 else if _right.type inherits ArrayType 785 pass 784 786 else if not _right.type.isDynamic 785 787 # try to use right.contains(left) -
cobra/trunk/Source/Members.cobra
r2299 r2310 756 756 757 757 def unNilReturnType is override 758 assert _returnType is nil 759 if _returnTypeNode inherits NilableTypeProxy 758 if _returnType 759 if _returnType inherits NilableType 760 _returnType = _returnType.nonNil 761 else if _returnTypeNode inherits NilableTypeProxy 760 762 _returnTypeNode = _returnTypeNode.innerTypeProxy 761 763 … … 1274 1276 1275 1277 def unNilReturnType is override 1276 assert _returnType is nil 1277 if _returnTypeNode inherits NilableTypeProxy 1278 if _returnType 1279 if _returnType inherits NilableType 1280 _returnType = _returnType.nonNil 1281 else if _returnTypeNode inherits NilableTypeProxy 1278 1282 _returnTypeNode = _returnTypeNode.innerTypeProxy 1279 1283 -
cobra/trunk/Source/Types.cobra
r2304 r2310 673 673 def isEquatableTo(t as IType) as bool 674 674 t = t.nonNil 675 if this == t 676 return true 677 if .isAssignableTo(t) or t.isAssignableTo(this) 678 return true 675 if this == t, return true 676 if .isAssignableTo(t) or t.isAssignableTo(this), return true 679 677 return false 680 678 681 679 get nonNil as IType 680 ensure not result inherits NilableType 682 681 return this 683 682 … … 770 769 Returns a named member of System.Object by default. 771 770 """ 772 assert .didBindInh and .didBindInt 771 assert .didBindInh and .didBindInt # don't `require` because subclass overrides may check and fix before invoking base 773 772 objectClass = .compiler.objectType 774 773 return objectClass.memberForName(name) … … 969 968 member = base.memberForName(name) 970 969 if member is nil 971 member = _box.symbolForName(name, true) 970 member = _box.symbolForName(name, true) # TODO: should that be .memberForName instead of .symbolForName? 972 971 return member 973 972 974 973 def isAssignableTo(type as IType) as bool 975 974 r = base.isAssignableTo(type) 976 if not r 977 r = _systemAliasType == type 975 if not r, r = _systemAliasType == type 978 976 return r 979 977 … … 985 983 986 984 def isComparableTo(t as IType) as bool 987 if this is t 988 return true 989 else 990 return base.isComparableTo(t) 985 return this is t or base.isComparableTo(t) 991 986 992 987 … … 1343 1338 1344 1339 .nilableType(t) 1340 1341 Note that NilableType will not wrap another NilableType. Also, .typeProvider.nilableType(t) 1342 silently handles this so in practice you don't have to guard against it. 1345 1343 """ 1346 1344 1347 1345 cue init(t as IType?) 1346 require not t inherits NilableType 1348 1347 base.init(t) 1349 1348 … … 1409 1408 return .typeProvider.nilableType(_wrappedType.greatestCommonDenominatorWith(type)) 1410 1409 1410 def secondaryConstructedTypeFor(box as Box, gpToType as Dictionary<of GenericParam, IType>) as IType is override 1411 wt = _wrappedType.secondaryConstructedTypeFor(box, gpToType) 1412 if not wt inherits NilableType 1413 thisType = .getType 1414 return thisType(wt) 1415 else 1416 return wt 1417 1411 1418 def suggestionsForBadMemberName(name as String) as List<of String> is override 1412 1419 return _wrappedType.suggestionsForBadMemberName(name) … … 1683 1690 Node.typeProvider = saveTP 1684 1691 1685 var _box as Box?1686 1687 1692 cue init(wrappedType as IType?) 1688 1693 base.init(wrappedType) … … 1697 1702 return true 1698 1703 1704 get box from var as Box? 1705 1699 1706 get name as String is override 1700 1707 return _wrappedType.name + r'[]' … … 1704 1711 1705 1712 def isAssignableTo(type as IType) as bool is override 1706 if base.isAssignableTo(type) 1707 return true 1713 if base.isAssignableTo(type), return true 1708 1714 if type inherits ArrayType 1709 if _wrappedType == type.theWrappedType 1710 return true 1715 if _wrappedType == type.theWrappedType, return true 1711 1716 # covariance with arrays 1712 if _wrappedType.isAssignableTo(type.theWrappedType) 1713 return true 1717 if _wrappedType.isAssignableTo(type.theWrappedType), return true 1714 1718 if type inherits StreamType 1715 if .isAssignableTo(type.box to !) 1716 return true 1719 if .isAssignableTo(type.box to !), return true 1717 1720 # covariance with streams 1718 if _wrappedType.isAssignableTo(type.innerType to !) 1719 return true 1720 return false 1721 if _wrappedType.isAssignableTo(type.innerType to !), return true 1722 if _box.isAssignableTo(type), return true 1723 return false 1724 1725 def isDescendantOf(type as IType) as bool 1726 return base.isDescendantOf(type) or .box.isDescendantOf(type) 1727 1728 def memberForName(name as String) as IMember? is override 1729 m = base.memberForName(name) 1730 if m is nil, m = .box.memberForName(name) 1731 # TODO: dup'ed from StreamType: 1732 if m is nil and _box and .compiler and .compiler.nodeStack.count and (.compiler.nodeStack.peek to Node).isBindingImp 1733 # look for an extension member, but it has to be accessible according to namespaces 1734 if .compiler.nameSpaceStack.count 1735 # don't need to go through the whole namespace stack because the namespace will check its parent 1736 m = .compiler.curNameSpace.extensionMemberFor(_box to !, name) 1737 return m 1738 1739 def suggestionsForBadMemberName(name as String) as List<of String> is override 1740 return .box.suggestionsForBadMemberName(name) 1721 1741 1722 1742 def _bindInh 1723 1743 base._bindInh 1724 _superType = .compiler.enumerableOfType.constructedTypeFor([.theWrappedType]) 1725 1726 def memberForName(name as String) as IMember? 1727 member = base.memberForName(name) 1728 if member is nil 1729 if _box is nil 1730 # TODO: make members based on System.Array 1731 _box = Class(Token.empty, Token.empty, '[.getType.name]_[.serialNum]', List<of IType>(), List<of String>(), AttributeList(), nil, List<of ITypeProxy>(), List<of ITypeProxy>(), nil) 1732 indexer = Indexer(Token.empty, Token.empty, _box, r'[]', [Param(Token('', 1, 1, 1, 'ID', 'index', nil), .compiler.intType)], _wrappedType, List<of String>(), AttributeList(), '') 1733 _box.addDecl(indexer) 1734 lengthProp = Property(Token.empty, Token.empty, _box, 'length', .compiler.intType, List<of String>(), AttributeList(), '') 1735 _box.addDecl(lengthProp) 1736 _box.bindAll 1737 member = _box.symbolForName(name, true) 1738 return member 1744 if .compiler # will be nil during unit tests 1745 iclone = .compiler.libraryType('System.ICloneable') 1746 icoll = (.compiler.libraryType('System.Collections.Generic.ICollection<of>') to Box).constructedTypeFor([.theWrappedType]) 1747 ienum = .compiler.enumerableOfType.constructedTypeFor([.theWrappedType]) 1748 # TODO: ilist = .compiler.ilistOfType.constructedTypeFor([.theWrappedType]) 1749 interfaces = [iclone to ITypeProxy, icoll, ienum] # TODO:, ilist] -- problems with cobra -ert:yes hello and extension method String.split 1750 _box = Class(Token.empty, Token.empty, '[.getType.name]_[.serialNum]', List<of IType>(), List<of String>(), AttributeList(), nil, interfaces, List<of ITypeProxy>(), nil) 1751 # TODO: make members based on System.Array 1752 indexer = Indexer(Token.empty, Token.empty, _box, r'[]', [Param(Token('', 1, 1, 1, 'ID', 'index', nil), .compiler.intType)], _wrappedType, List<of String>(), AttributeList(), '') 1753 _box.addDecl(indexer) 1754 lengthProp = Property(Token.empty, Token.empty, _box, 'length', .compiler.intType, List<of String>(), AttributeList(), '') 1755 _box.addDecl(lengthProp) 1756 _box.bindInh 1757 _superType = _box 1758 1759 def _bindInt 1760 base._bindInt 1761 _box.bindInt 1762 1763 def _bindImp 1764 base._bindImp 1765 _box.bindImp 1739 1766 1740 1767 -
cobra/trunk/Tests/700-command-line/112-run-hello.cobra
r1886 r2310 39 39 40 40 assert p.exitCode == 0 41 assert output.trim == 'Hello' 41 assert output.trim == 'Hello', args 42 42 43 43 def flush



