This makes categories of NSString, NSArray, and NSDictionary available
on String, Array, and Dictionary. Note that we only consider
categories not present in the Objective-C Foundation module, because
we want to manually map those APIs ourselves. Hence, no changes to the
NSStringAPI. Implements <rdar://problem/13653329>.
Swift SVN r18920
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.
Swift SVN r18865
Allow class metatypes (including class-constrained existential metatypes) to be treated as subtypes of AnyObject, and single-@objc protocol metatypes to be treated as subtypes of the Protocol class from objc. No codegen support yet, so this is hidden behind a frontend flag for now.
Swift SVN r18810
One difficulty in generating reasonable diagnostic data for type check failures has been the fact that many constraints had been synthesized without regard for where they were rooted in the program source. The result of this was that even though we would store failure information for specific constraints, we wouldn't emit it for lack of a source location. By making location data a non-optional component of constraints, we can begin diagnosing type check errors closer to their point of failure.
Swift SVN r18751
We removed this feature when we changed casting syntax, but left it in
the type checker to help migrate code via a Fix-It. We no longer need
it.
Swift SVN r18729
Rather than only allowing downcasting from AnyObject, allow it for any
class or Objective-C existential type, e.g., "NSArray() as
Int[]". While here, reduce our reliance on implicit conversions when
checking bridging. This is most of <rdar://problem/16972956>, but 'is'
still doesn't work properly in these cases.
Swift SVN r18693
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Some minor tweaks this time around for better interoperability with AnyObject.)
Swift SVN r18498
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)
Swift SVN r18473
Previously, we were relying on user-defined conversions to perform the
final bridging from the Objective-C class type (e.g., NSString) to its
Swift value type (String). That works for NSString <-> String, but not
for arbitrary arrays. Use the bridgeFromObjectiveC() witness instead,
so we can handle:
let obj: AnyObject = ...
let strArr: String[] = obj!
Fixes <rdar://problem/16952771>.
Swift SVN r18422
The latter has some brilliant code to deal with differing levels of
optionality, binding inner optionals etc. Unifying these code paths
makes array downcasts work when the source has (possibly
implicitly-wrapped) optional type, e.g.,
var arrImplicitOpt: AnyObject[]! = nsarr
if let strArr = arrImplicitOpt as String[] {
println("String array contains \(strArr)")
} else {
println("Not a string array")
}
Another part of <rdar://problem/16952771> and the array-bridging story.
Swift SVN r18392
This allows us to cast "through" a bridged class type in an "as" case,
e.g.,
if let str = obj as String { ... }
where obj is an AnyObject (or optional/implicitly unwrapped optional
thereof). In such cases, we perform a checked cast to the
corresponding class type (NSString in this case) and then convert the
(optional!) result down to the value type.
Addresses the main part of <rdar://problem/15288553>, but we still
have trouble with "is" with optionals, and the #if false'd out
testcase incorrectly fails due to <rdar://problem/16953860>.
Swift SVN r18347
upcasts."
Reinstate "Restrict the array-bridged conversion to non-verbatim
bridging."
Reinstate "[stdlib] Fix T[].bridgeFromObjectiveC"
Reinstate "[stdlib] Fix T[].bridgeFromObjectiveC"
Reinstate "[stdlib] Move _arrayBridgedDownCast to Foundation"
Reinstate "Replace "can" with "cannot" in a message."
Reinstate "Implement support for non-verbatim T[] -> AnyObject[]
upcasts."
This reinstates commit r18291.
This reinstates commit r18290.
This reinstates commit r18288.
This reinstates commit r18287.
This reinstates commit r18286.
This reinstates commit r18293.
This reinstates commit r18283.
John fixed the issue in r18294.
Swift SVN r18299
Revert "Restrict the array-bridged conversion to non-verbatim bridging."
Revert "[stdlib] Fix T[].bridgeFromObjectiveC"
Revert "[stdlib] Fix T[].bridgeFromObjectiveC"
Revert "[stdlib] Move _arrayBridgedDownCast to Foundation"
Revert "Replace "can" with "cannot" in a message."
Revert "Implement support for non-verbatim T[] -> AnyObject[] upcasts."
This reverts commit r18291.
This reverts commit r18290.
This reverts commit r18288.
This reverts commit r18287.
This reverts commit r18286.
This reverts commit r18293.
This reverts commit r18283.
Sorry for the number of reverts, but I needed to do this many to get a clean
revert to r18283.
Swift SVN r18296
Previously, we were relying on overly-general subtyping to determine
when we could perform an array upcast, which pushed some non-verbatim
bridging through that path. Instead, restrict array upcasts to classes
and ObjC existentials, and use bridging casts for the other cases.
Swift SVN r18291
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>
Swift SVN r17957
Use protocol conformance checks whenever we want to determine whether
a value type is bridged to an Objective-C class, which is simpler and
more robust. Clean up some of the type checker code around bridging,
using TypeBase::isEqual() to compare types and looking through type
sugar more regularly.
As part of this, move Array's conformance to
_ConditionallyBridgedToObjectiveC into the Foundation overlay. This
lets us use NSArray as the bridged type (which is clearer than using
CocoaArray), and follows what we're doing for dictionary bridging.
As part of this, move Array's bridged-to-
Swift SVN r17868
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.
Swift SVN r17798
This is fairly ugly, because we're halfway between a-function-type-takes-a-tuple and a-function-type-takes-a-set-of-parameters. However, it's another step toward -strict-keyword-arguments.
Swift SVN r17727
Introduce a new locator kind for argument/parameter comparisons that
tracks both the argument and the parameter, which we will eventually
use in diagnostics more regularly. For now, this helps us smooth over
scalar-to-tuple/tuple-to-tuple/tuple-to-scalar nonsense when dealing
with calls.
Fix a pile of fallout from this change.
Swift SVN r17648
We're going to want to re-use the argument/parameter matching of
matchCallArguments() elsewhere, so separate it from the constraint system.
Swift SVN r17626
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.
Swift SVN r17557
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.
Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)
This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.
<rdar://problem/16808651>. Part of the Playground performance efforts.
Swift SVN r17524