Files
swift-mirror/test/expr/cast/set_downcast.swift
2020-07-05 22:55:56 -03:00

37 lines
674 B
Swift

// RUN: %target-typecheck-verify-swift
class C : Hashable {
var x = 0
func hash(into hasher: inout Hasher) {
hasher.combine(x)
}
}
func == (x: C, y: C) -> Bool { return true }
class D : C {}
// Unrelated to the classes above.
class U : Hashable {
func hash(into hasher: inout Hasher) {}
}
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 _ = setC as? Set<D> { }
// Test set downcasts to unrelated types.
_ = setC as! Set<U> // Ok
// Test set conditional downcasts to unrelated types.
if let _ = setC as? Set<U> { } // Ok