Skip to content

Commit 4132aa0

Browse files
committed
[Tests] NFC: Update all of the test-cases improved by changes to generic argument mismatch handling
1 parent 7305275 commit 4132aa0

25 files changed

+120
-49
lines changed

test/ClangImporter/MixedSource/mixed-target-using-header.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ func testProtocolNamingConflict() {
6666
let a: ConflictingName1?
6767
var b: ConflictingName1Protocol?
6868
b = a // expected-error {{cannot assign value of type 'ConflictingName1?' to type '(any ConflictingName1Protocol)?'}}
69+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('ConflictingName1' and 'any ConflictingName1Protocol') are expected to be equal}}
6970
_ = b
7071

7172
let c: ConflictingName2?
7273
var d: ConflictingName2Protocol?
7374
d = c // expected-error {{cannot assign value of type 'ConflictingName2?' to type '(any ConflictingName2Protocol)?'}}
75+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('ConflictingName2' and 'any ConflictingName2Protocol') are expected to be equal}}
7476
_ = d
7577
}
7678

test/ClangImporter/cf.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func testOutParametersGood() {
118118
func testOutParametersBad() {
119119
let fridge: CCRefrigerator?
120120
CCRefrigeratorCreateIndirect(fridge) // expected-error {{cannot convert value of type 'CCRefrigerator?' to expected argument type 'UnsafeMutablePointer<CCRefrigerator?>?'}}
121+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('CCRefrigerator' and 'UnsafeMutablePointer<CCRefrigerator?>') are expected to be equal}}
121122

122123
let power: CCPowerSupply?
123124
CCRefrigeratorGetPowerSupplyIndirect(0, power)
@@ -128,21 +129,26 @@ func testOutParametersBad() {
128129
CCRefrigeratorGetItemUnaudited(0, 0, item)
129130
// expected-error@-1:34 {{cannot convert value of type 'Int' to expected argument type 'CCRefrigerator'}}
130131
// expected-error@-2:40 {{cannot convert value of type 'CCItem?' to expected argument type 'UnsafeMutablePointer<Unmanaged<CCItem>?>?'}}
132+
// expected-note@-3 {{arguments to generic parameter 'Wrapped' ('CCItem' and 'UnsafeMutablePointer<Unmanaged<CCItem>?>') are expected to be equal}}
131133
}
132134

133135
func nameCollisions() {
134136
var objc: MyProblematicObject?
135137
var cf: MyProblematicObjectRef?
136138
cf = objc // expected-error {{cannot assign value of type 'MyProblematicObject?' to type 'MyProblematicObjectRef?'}}
139+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('MyProblematicObject' and 'MyProblematicObjectRef') are expected to be equal}}
137140
objc = cf // expected-error {{cannot assign value of type 'MyProblematicObjectRef?' to type 'MyProblematicObject?'}}
141+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('MyProblematicObjectRef' and 'MyProblematicObject') are expected to be equal}}
138142

139143
var cfAlias: MyProblematicAliasRef?
140144
cfAlias = cf // okay
141145
cf = cfAlias // okay
142146

143147
var otherAlias: MyProblematicAlias?
144148
otherAlias = cfAlias // expected-error {{cannot assign value of type 'MyProblematicAliasRef?' (aka 'Optional<MyProblematicObjectRef>') to type 'MyProblematicAlias?' (aka 'Optional<Float>')}}
149+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('MyProblematicAliasRef' (aka 'MyProblematicObjectRef') and 'MyProblematicAlias' (aka 'Float')) are expected to be equal}}
145150
cfAlias = otherAlias // expected-error {{cannot assign value of type 'MyProblematicAlias?' (aka 'Optional<Float>') to type 'MyProblematicAliasRef?' (aka 'Optional<MyProblematicObjectRef>')}}
151+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('MyProblematicAlias' (aka 'Float') and 'MyProblematicAliasRef' (aka 'MyProblematicObjectRef')) are expected to be equal}}
146152

147153
func isOptionalFloat(_: inout Optional<Float>) {}
148154
isOptionalFloat(&otherAlias) // okay

test/ClangImporter/ctypes_parse.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func testFunctionPointers() {
214214

215215
useFunctionPointer2(anotherFP)
216216
sizedFP = fp // expected-error {{cannot assign value of type 'fptr?' (aka 'Optional<@convention(c) (Int32) -> Int32>') to type '(@convention(c) (CInt, CInt, UnsafeMutableRawPointer?) -> Void)?'}}
217+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('fptr' (aka '@convention(c) (Int32) -> Int32') and '@convention(c) (CInt, CInt, UnsafeMutableRawPointer?) -> Void'}}
217218
}
218219

219220
func testStructDefaultInit() {

test/Constraints/bridging-nsnumber-and-nsvalue.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func bridgeNSNumberBackToSpecificType(object: ${ObjectType},
6262
_ = object as? ${Type}
6363
_ = object as! ${Type}
6464

65-
_ = optional as ${Type}? // expected-error{{is not convertible to}} expected-note {{use 'as!'}}
65+
_ = optional as ${Type}? // expected-error{{cannot convert value of type '${ObjectType}?' to type '${Type}?' in coercion}} expected-note {{arguments to generic parameter 'Wrapped' ('${ObjectType}' and '${Type}') are expected to be equal}}
6666
_ = optional is ${Type}?
6767
_ = optional as? ${Type}?
6868
_ = optional as! ${Type}?

test/Constraints/bridging.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,17 @@ func rdar19831698() {
283283
// <rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions
284284
func rdar19836341(_ ns: NSString?, vns: NSString?) {
285285
var vns = vns
286-
let _: String? = ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{22-22= as String?}}
287-
var _: String? = ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{22-22= as String?}}
286+
let _: String? = ns // expected-error{{cannot assign value of type 'NSString?' to type 'String?'}}{{22-22= as String?}}
287+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('NSString' and 'String') are expected to be equal}}
288+
var _: String? = ns // expected-error{{cannot assign value of type 'NSString?' to type 'String?'}}{{22-22= as String?}}
289+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('NSString' and 'String') are expected to be equal}}
288290

289291
// Important part about below diagnostic is that from-type is described as
290292
// 'NSString?' and not '@lvalue NSString?':
291-
let _: String? = vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{23-23= as String?}}
292-
var _: String? = vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{23-23= as String?}}
293+
let _: String? = vns // expected-error{{cannot assign value of type 'NSString?' to type 'String?'}}{{23-23= as String?}}
294+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('NSString' and 'String') are expected to be equal}}
295+
var _: String? = vns // expected-error{{cannot assign value of type 'NSString?' to type 'String?'}}{{23-23= as String?}}
296+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('NSString' and 'String') are expected to be equal}}
293297

294298
vns = ns
295299
}
@@ -300,15 +304,17 @@ func rdar20029786(_ ns: NSString?) {
300304
// expected-error@-1 {{cannot convert value of type 'NSString?' to expected argument type 'String?'}} {{21-21= as String?}}
301305
var s2 = ns ?? "str" as String as String // expected-error {{binary operator '??' cannot be applied to operands of type 'NSString?' and 'String'}}
302306

303-
let s3: NSString? = "str" as String? // expected-error {{cannot convert value of type 'String?' to specified type 'NSString?'}}{{39-39= as NSString?}}
307+
let s3: NSString? = "str" as String? // expected-error {{cannot assign value of type 'String?' to type 'NSString?'}}{{39-39= as NSString?}}
308+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('String' and 'NSString') are expected to be equal}}
304309

305310
var s4: String = ns ?? "str" // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}} {{20-20=(}} {{31-31=) as String}}
306311
var s5: String = (ns ?? "str") as String // fixed version
307312
}
308313

309314
// Make sure more complicated cast has correct parenthesization
310315
func castMoreComplicated(anInt: Int?) {
311-
let _: (NSObject & NSCopying)? = anInt // expected-error{{cannot convert value of type 'Int?' to specified type '(any NSObject & NSCopying)?'}}{{41-41= as (any NSObject & NSCopying)?}}
316+
let _: (NSObject & NSCopying)? = anInt // expected-error{{cannot assign value of type 'Int?' to type '(any NSObject & NSCopying)?'}}{{41-41= as (any NSObject & NSCopying)?}}
317+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('Int' and 'any NSObject & NSCopying') are expected to be equal}}
312318
}
313319

314320

test/Constraints/casts_objc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func optionalityMismatchingCasts(f: CGFloat, n: NSNumber, fooo: CGFloat???,
8282
nooo: NSNumber???) {
8383
_ = f as NSNumber?
8484
_ = f as NSNumber??
85-
let _ = fooo as NSNumber?? // expected-error{{'CGFloat???' is not convertible to 'NSNumber??'}}
86-
//expected-note@-1 {{did you mean to use 'as!' to force downcast?}} {{16-18=as!}}
85+
let _ = fooo as NSNumber?? // expected-error{{cannot convert value of type 'CGFloat???' to type 'NSNumber??' in coercion}}
86+
//expected-note@-1 {{arguments to generic parameter 'Wrapped' ('CGFloat?' and 'NSNumber') are expected to be equal}}
8787
let _ = fooo as NSNumber???? // okay: injects extra optionals
8888
}
8989

test/Constraints/fixes.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,14 @@ struct Q {
158158
let s: String?
159159
}
160160
let q = Q(s: nil)
161-
let a: Int? = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}}
162-
// expected-error@-1 {{cannot convert value of type 'String.UTF8View?' to specified type 'Int?'}}
163-
// expected-note@-2{{chain the optional using '?'}}{{18-18=?}}
164-
let b: Int = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}}
161+
let a: Int? = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}} expected-note {{chain the optional using '?'}}{{18-18=?}}
162+
// expected-error@-1 {{cannot assign value of type 'String.UTF8View?' to type 'Int?'}}
163+
// expected-note@-2 {{arguments to generic parameter 'Wrapped' ('String.UTF8View' and 'Int') are expected to be equal}}
164+
let b: Int = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}} expected-note {{chain the optional using '?'}}{{17-17=?}} expected-note {{force-unwrap using '!'}}{{17-17=!}}
165165
// expected-error@-1 {{cannot convert value of type 'String.UTF8View' to specified type 'Int'}}
166-
// expected-note@-2{{chain the optional using '?'}}{{17-17=?}}
167-
// expected-note@-3{{force-unwrap using '!'}}{{17-17=!}}
168-
let d: Int! = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}}
169-
// expected-error@-1 {{cannot convert value of type 'String.UTF8View?' to specified type 'Int?'}}
170-
// expected-note@-2{{chain the optional using '?'}}{{18-18=?}}
166+
let d: Int! = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}} expected-note {{chain the optional using '?'}}{{18-18=?}}
167+
// expected-error@-1 {{cannot assign value of type 'String.UTF8View?' to type 'Int?'}}
168+
// expected-note@-2 {{arguments to generic parameter 'Wrapped' ('String.UTF8View' and 'Int') are expected to be equal}}
171169
let c = q.s.utf8 // expected-error{{value of optional type 'String?' must be unwrapped to refer to member 'utf8' of wrapped base type 'String'}}
172170
// expected-note@-1{{chain the optional using '?' to access member 'utf8' only for non-'nil' base values}}{{12-12=?}}
173171
// expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}{{12-12=!}}

test/Constraints/invalid_implicit_conversions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func test(
2929

3030
takesAutoclosure(rawPtr, a) // expected-error {{cannot perform pointer conversion of value of type '[Int]' to autoclosure result type 'UnsafeRawPointer'}}
3131
takesAutoclosure(ptr, a) // expected-error {{cannot perform pointer conversion of value of type '[Int]' to autoclosure result type 'UnsafePointer<Int>'}}
32-
takesAutoclosure(optPtr, b) // expected-error {{cannot perform pointer conversion of value of type '[Int]?' to autoclosure result type 'UnsafePointer<Int>?'}}
32+
takesAutoclosure(optPtr, b) // expected-error {{conflicting arguments to generic parameter 'T' ('UnsafePointer<Int>?' vs. '[Int]?')}}
3333

3434
takesAutoclosure(rawPtr, s) // expected-error {{cannot perform pointer conversion of value of type 'String' to autoclosure result type 'UnsafeRawPointer'}}
3535
takesAutoclosure(ptrI8, s) // expected-error {{cannot perform pointer conversion of value of type 'String' to autoclosure result type 'UnsafePointer<Int8>'}}

test/Constraints/issue-81023.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/swiftlang/swift/issues/81023
4+
5+
protocol MyPublisher {
6+
associatedtype Output
7+
associatedtype Failure: Error
8+
func eraseToAnyPublisher() -> MyAnyPublisher<Output, Failure>
9+
}
10+
11+
extension MyPublisher {
12+
func eraseToAnyPublisher() -> MyAnyPublisher<Output, Failure> {
13+
fatalError()
14+
}
15+
}
16+
17+
struct MyAnyPublisher<Output, Failure: Error>: MyPublisher {}
18+
struct MyJust<Output>: MyPublisher {
19+
typealias Failure = Never
20+
init(_ value: Output) {}
21+
}
22+
23+
extension MyPublisher where Output == (any Collection)? { // expected-note {{where 'Self.Output' = '[Int]?'}}
24+
func mapCount() -> MyAnyPublisher<Int, Failure> { fatalError() }
25+
}
26+
27+
func test(myPub: MyAnyPublisher<[Int]?, Never>) {
28+
myPub.mapCount()
29+
// expected-error@-1 {{referencing instance method 'mapCount()' on 'MyPublisher' requires the types '[Int]?' and '(any Collection)?' be equivalent}}
30+
}

test/Constraints/iuo.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ let _ = (returnsIUO as () -> Int)() // expected-error {{cannot convert value of
216216
// Make sure we only permit an IUO unwrap on the first application.
217217
func returnsIUOFn() -> (() -> Int?)! { nil }
218218
let _: (() -> Int?)? = returnsIUOFn()
219-
let _: (() -> Int)? = returnsIUOFn() // expected-error {{cannot convert value of type '(() -> Int?)?' to specified type '(() -> Int)?'}}
219+
let _: (() -> Int)? = returnsIUOFn() // expected-error {{cannot assign value of type '(() -> Int?)?' to type '(() -> Int)?'}}
220+
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('() -> Int?' and '() -> Int') are expected to be equal}}
220221
let _: () -> Int? = returnsIUOFn()
221222
let _: () -> Int = returnsIUOFn() // expected-error {{cannot convert value of type '(() -> Int?)?' to specified type '() -> Int'}}
222223
let _: Int? = returnsIUOFn()()

0 commit comments

Comments
 (0)