Files
swift-mirror/test/Interpreter/SDK/protocol_lookup_foreign.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

42 lines
954 B
Swift

// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: objc_interop
// REQUIRES: OS=macosx
import Foundation
protocol Fooable {
func foo()
}
func fooify<T>(x: T) {
if let foo = x as? Fooable {
foo.foo()
} else {
println("not fooable")
}
}
extension NSRect: Fooable {
func foo() { println("NSRect") }
}
extension CFSet: Fooable {
func foo() { println("CFSet") }
}
extension NSString: Fooable {
func foo() { println("NSString") }
}
fooify(NSRect()) // CHECK: NSRect
fooify(NSPoint()) // CHECK-NEXT: not fooable
// FIXME: CF types get their ObjC class dynamically looked up during dynamic
// casting.
fooify(CFSetCreate(kCFAllocatorDefault, nil, 0, nil)!) // TODO-NEXT: CFSet CHECK-NEXT: not fooable
fooify(CFArrayCreate(kCFAllocatorDefault, nil, 0, nil)!) // CHECK-NEXT: not fooable
fooify(NSString()) // CHECK-NEXT: NSString
fooify(NSMutableString()) // CHECK-NEXT: NSString
fooify(NSSet()) // CHECK-NEXT: not fooable