|
61 | 61 | }
|
62 | 62 | }
|
63 | 63 |
|
| 64 | +// ambiguities related to ~= |
| 65 | +protocol _Error: Error {} |
| 66 | + |
| 67 | +extension _Error { |
| 68 | + public static func ~=(lhs: Self, rhs: Self) -> Bool { |
| 69 | + false |
| 70 | + } |
| 71 | + |
| 72 | + public static func ~=(lhs: Error, rhs: Self) -> Bool { |
| 73 | + false |
| 74 | + } |
| 75 | + |
| 76 | + public static func ~=(lhs: Self, rhs: Error) -> Bool { |
| 77 | + false |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +enum CustomError { |
| 82 | + case A |
| 83 | +} |
| 84 | + |
| 85 | +extension CustomError: _Error {} |
| 86 | + |
| 87 | +func f(e: CustomError) { |
| 88 | + if e ~= CustomError.A {} |
| 89 | +} |
| 90 | + |
| 91 | +// Generic overload should be preferred over concrete one because the latter is non-default literal |
| 92 | +struct Pattern {} |
| 93 | + |
| 94 | +func ~= (pattern: Pattern, value: String) -> Bool { |
| 95 | + return false |
| 96 | +} |
| 97 | + |
| 98 | +extension Pattern: ExpressibleByStringLiteral { |
| 99 | + init(stringLiteral value: String) {} |
| 100 | +} |
| 101 | + |
| 102 | +func test_default_tilda(v: String) { |
| 103 | + _ = "hi" ~= v // Ok |
| 104 | +} |
| 105 | + |
| 106 | +struct UUID {} |
| 107 | + |
| 108 | +struct LogKey { |
| 109 | + init(base: some CustomStringConvertible, foo: Int = 0) { |
| 110 | + } |
| 111 | + |
| 112 | + init(base: UUID, foo: Int = 0) { |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +@available(swift 99) |
| 117 | +extension LogKey { |
| 118 | + init(base: String?) { |
| 119 | + } |
| 120 | + |
| 121 | + init(base: UUID?) { |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +func test_that_unavailable_init_is_not_used(x: String?) { |
| 126 | + _ = LogKey(base: x ?? "??") |
| 127 | +} |
| 128 | + |
| 129 | +// error: value of optional type 'UID?' must be unwrapped to a value of type 'UID' |
| 130 | +struct S: Comparable { |
| 131 | + static func <(lhs: Self, rhs: Self) -> Bool { |
| 132 | + false |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +func max(_ a: S?, _ b: S?) -> S? { |
| 137 | + nil |
| 138 | +} |
| 139 | + |
| 140 | +func test_stdlib_max_selection(s: S) -> S { |
| 141 | + let new = max(s, s) |
| 142 | + return new // Ok |
| 143 | +} |
| 144 | + |
| 145 | +// error: initializer for conditional binding must have Optional type, not 'UnsafeMutablePointer<Double>' |
| 146 | +do { |
| 147 | + struct TestPointerConversions { |
| 148 | + var p: UnsafeMutableRawPointer { get { fatalError() } } |
| 149 | + |
| 150 | + func f(_ p: UnsafeMutableRawPointer) { |
| 151 | + guard let x = UnsafeMutablePointer<Double>(OpaquePointer(self.p)) else { |
| 152 | + return |
| 153 | + } |
| 154 | + _ = x |
| 155 | + |
| 156 | + guard let x = UnsafeMutablePointer<Double>(OpaquePointer(p)) else { |
| 157 | + return |
| 158 | + } |
| 159 | + _ = x |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +// error: initializer 'init(_:)' requires that 'T' conform to 'BinaryInteger' |
| 165 | +do { |
| 166 | + struct Config { |
| 167 | + subscript<T>(_ key: String) -> T? { nil } |
| 168 | + subscript(_ key: String) -> Any? { nil } |
| 169 | + } |
| 170 | + |
| 171 | + struct S { |
| 172 | + init(maxQueueDepth: UInt) {} |
| 173 | + } |
| 174 | + |
| 175 | + func f(config: Config) { |
| 176 | + let maxQueueDepth = config["hi"] ?? 256 |
| 177 | + _ = S(maxQueueDepth: UInt(maxQueueDepth)) |
| 178 | + } |
| 179 | +} |
| 180 | + |
0 commit comments