Files
swift-mirror/test/expr/cast/set_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

39 lines
728 B
Swift

// RUN: %target-parse-verify-swift
class C : Hashable {
var x = 0
var hashValue: Int {
return x
}
}
func == (x: C, y: C) -> Bool { return true }
class D : C {}
// Unrelated to the classes above.
class U : Hashable {
var hashValue: Int {
return 0
}
}
func == (x: U, y: U) -> Bool { return true }
var setC = Set<C>()
var setD = Set<D>()
// Test set forced downcasts
setD = setC as! Set<D>
// Test set conditional downcasts
if let setD = setC as? Set<D> { }
// Test set downcasts to unrelated types.
setC as! Set<U> // expected-error{{'U' is not a subtype of 'C'}}
// Test set conditional downcasts to unrelated types
if let setU = setC as? Set<U> { } // expected-error{{'U' is not a subtype of 'C'}}