Files
swift-mirror/test/expr/cast/array_downcast.swift
Chris Lattner 31c01eab73 Change the meaning of "if let x = foo()" back to Xcode 6.4 semantics. The compiler
includes a number of QoI things to help people write the correct code.  I will commit
the testcase for it as the next patch.

The bulk of this patch is moving the stdlib, testsuite and validation testsuite to
the new syntax.  I moved a few uses of "as" patterns back to as? expressions in the 
stdlib as well.



Swift SVN r27959
2015-04-30 04:38:13 +00:00

85 lines
1.4 KiB
Swift

// RUN: %target-parse-verify-swift
// XFAIL: linux
class V {}
class U : V {}
class T : U {}
var v = V()
var u = U()
var t = T()
var va = [v]
var ua = [u]
var ta = [t]
va = ta
var va2: ([V])? = va as [V]
var v2: V = va2![0]
var ua2: ([U])? = va as? [U]
var u2: U = ua2![0]
var ta2: ([T])? = va as? [T]
var t2: T = ta2![0]
// Check downcasts that require bridging.
class A {
var x = 0
}
struct B : _ObjectiveCBridgeable {
static func _isBridgedToObjectiveC() -> Bool {
return true
}
static func _getObjectiveCType() -> Any.Type {
return A.self
}
func _bridgeToObjectiveC() -> A {
return A()
}
static func _forceBridgeFromObjectiveC(
x: A,
inout result: B?
) {
}
static func _conditionallyBridgeFromObjectiveC(
x: A,
inout result: B?
) -> Bool {
return true
}
}
func testBridgedDowncastAnyObject(arr: [AnyObject], arrOpt: [AnyObject]?,
arrIUO: [AnyObject]!) {
var b = B()
if let bArr = arr as? [B] {
b = bArr[0]
}
if let bArr = arrOpt as? [B] {
b = bArr[0]
}
if let bArr = arrIUO as? [B] {
b = bArr[0]
}
}
func testBridgedIsAnyObject(arr: [AnyObject], arrOpt: [AnyObject]?,
arrIUO: [AnyObject]!) -> Bool {
var b = B()
if arr is [B] { return arr is [B] }
if arrOpt is [B] { return arrOpt is [B] }
if arrIUO is [B] { return arrIUO is [B] }
return false
}