[Tests] NFC: Add more test-cases that were previously solved due to old hacks behavior

This commit is contained in:
Pavel Yaskevich
2024-09-11 15:01:13 -07:00
parent 23589add74
commit d0ff6c81b8

View File

@@ -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))
}
}