Files
swift-mirror/test/Interpreter/conditional_conformances_runtime.swift
Saleem Abdulrasool b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00

43 lines
698 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test
protocol P {
func foo() -> Int
}
struct X : P {
func foo() -> Int { return 1 }
}
struct Y<T> {
var wrapped: T
}
extension Y: P where T: P {
func foo() -> Int { return wrapped.foo() + 10 }
}
func tryAsP(_ value: Any) -> Int {
if let p = value as? P {
return p.foo()
}
return 0
}
extension Dictionary: P where Value == (Key) -> Bool {
func foo() -> Int { return 2 }
}
let yx = Y(wrapped: X())
assert(tryAsP(yx) == 11)
let dict: [Int : (Int) -> Bool] = [:]
assert(tryAsP(dict) == 2)
let yDict = Y(wrapped: dict)
assert(tryAsP(yDict) == 12)