mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Tests] NFC: Add more test-cases that were previously solved due to old hacks behavior
This commit is contained in:
@@ -61,3 +61,120 @@ do {
|
||||
}
|
||||
}
|
||||
|
||||
// ambiguities related to ~=
|
||||
protocol _Error: Error {}
|
||||
|
||||
extension _Error {
|
||||
public static func ~=(lhs: Self, rhs: Self) -> Bool {
|
||||
false
|
||||
}
|
||||
|
||||
public static func ~=(lhs: Error, rhs: Self) -> Bool {
|
||||
false
|
||||
}
|
||||
|
||||
public static func ~=(lhs: Self, rhs: Error) -> Bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
enum CustomError {
|
||||
case A
|
||||
}
|
||||
|
||||
extension CustomError: _Error {}
|
||||
|
||||
func f(e: CustomError) {
|
||||
if e ~= CustomError.A {}
|
||||
}
|
||||
|
||||
// Generic overload should be preferred over concrete one because the latter is non-default literal
|
||||
struct Pattern {}
|
||||
|
||||
func ~= (pattern: Pattern, value: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
extension Pattern: ExpressibleByStringLiteral {
|
||||
init(stringLiteral value: String) {}
|
||||
}
|
||||
|
||||
func test_default_tilda(v: String) {
|
||||
_ = "hi" ~= v // Ok
|
||||
}
|
||||
|
||||
struct UUID {}
|
||||
|
||||
struct LogKey {
|
||||
init(base: some CustomStringConvertible, foo: Int = 0) {
|
||||
}
|
||||
|
||||
init(base: UUID, foo: Int = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
@available(swift 99)
|
||||
extension LogKey {
|
||||
init(base: String?) {
|
||||
}
|
||||
|
||||
init(base: UUID?) {
|
||||
}
|
||||
}
|
||||
|
||||
func test_that_unavailable_init_is_not_used(x: String?) {
|
||||
_ = LogKey(base: x ?? "??")
|
||||
}
|
||||
|
||||
// error: value of optional type 'UID?' must be unwrapped to a value of type 'UID'
|
||||
struct S: Comparable {
|
||||
static func <(lhs: Self, rhs: Self) -> Bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
func max(_ a: S?, _ b: S?) -> S? {
|
||||
nil
|
||||
}
|
||||
|
||||
func test_stdlib_max_selection(s: S) -> S {
|
||||
let new = max(s, s)
|
||||
return new // Ok
|
||||
}
|
||||
|
||||
// error: initializer for conditional binding must have Optional type, not 'UnsafeMutablePointer<Double>'
|
||||
do {
|
||||
struct TestPointerConversions {
|
||||
var p: UnsafeMutableRawPointer { get { fatalError() } }
|
||||
|
||||
func f(_ p: UnsafeMutableRawPointer) {
|
||||
guard let x = UnsafeMutablePointer<Double>(OpaquePointer(self.p)) else {
|
||||
return
|
||||
}
|
||||
_ = x
|
||||
|
||||
guard let x = UnsafeMutablePointer<Double>(OpaquePointer(p)) else {
|
||||
return
|
||||
}
|
||||
_ = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// error: initializer 'init(_:)' requires that 'T' conform to 'BinaryInteger'
|
||||
do {
|
||||
struct Config {
|
||||
subscript<T>(_ key: String) -> T? { nil }
|
||||
subscript(_ key: String) -> Any? { nil }
|
||||
}
|
||||
|
||||
struct S {
|
||||
init(maxQueueDepth: UInt) {}
|
||||
}
|
||||
|
||||
func f(config: Config) {
|
||||
let maxQueueDepth = config["hi"] ?? 256
|
||||
_ = S(maxQueueDepth: UInt(maxQueueDepth))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user