Skip to content

Commit 67d87e1

Browse files
committed
[Tests] NFC: Adjust all the test-cases improved by multi-statement inference
1 parent aa3b886 commit 67d87e1

20 files changed

+86
-82
lines changed

test/Constraints/closures.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct CC {}
252252
func callCC<U>(_ f: (CC) -> U) -> () {}
253253

254254
func typeCheckMultiStmtClosureCrash() {
255-
callCC { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}}
255+
callCC {
256256
_ = $0
257257
return 1
258258
}
@@ -312,24 +312,23 @@ func testAcceptNothingToInt(ac1: @autoclosure () -> Int) {
312312
struct Thing {
313313
init?() {}
314314
}
315-
// This throws a compiler error
316-
let things = Thing().map { thing in // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{34-34=-> <#Result#> }}
317-
// Commenting out this makes it compile
315+
316+
let things = Thing().map { thing in
318317
_ = thing
319318
return thing
320319
}
321320

322321

323322
// <rdar://problem/21675896> QoI: [Closure return type inference] Swift cannot find members for the result of inlined lambdas with branches
324323
func r21675896(file : String) {
325-
let x: String = { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{20-20= () -> <#Result#> in }}
324+
let x: String = {
326325
if true {
327326
return "foo"
328327
}
329328
else {
330329
return file
331330
}
332-
}().pathExtension
331+
}().pathExtension // expected-error {{value of type 'String' has no member 'pathExtension'}}
333332
}
334333

335334

@@ -360,7 +359,7 @@ func someGeneric19997471<T>(_ x: T) {
360359

361360

362361
// <rdar://problem/20921068> Swift fails to compile: [0].map() { _ in let r = (1,2).0; return r }
363-
[0].map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{5-5=-> <#Result#> }}
362+
let _ = [0].map {
364363
_ in
365364
let r = (1,2).0
366365
return r
@@ -408,7 +407,7 @@ func r20789423() {
408407
print(p.f(p)()) // expected-error {{cannot convert value of type 'C' to expected argument type 'Int'}}
409408
// expected-error@-1:11 {{cannot call value of non-function type '()'}}
410409

411-
let _f = { (v: Int) in // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{23-23=-> <#Result#> }}
410+
let _f = { (v: Int) in
412411
print("a")
413412
return "hi"
414413
}
@@ -1127,7 +1126,7 @@ func rdar76058892() {
11271126
func experiment(arr: [S]?) {
11281127
test { // expected-error {{contextual closure type '() -> String' expects 0 arguments, but 1 was used in closure body}}
11291128
if let arr = arr {
1130-
arr.map($0.test) // expected-note {{anonymous closure parameter '$0' is used here}}
1129+
arr.map($0.test) // expected-note {{anonymous closure parameter '$0' is used here}} // expected-error {{generic parameter 'T' could not be inferred}}
11311130
}
11321131
}
11331132
}

test/Constraints/diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func ***~(_: Int, _: String) { }
148148
i ***~ i // expected-error{{cannot convert value of type 'Int' to expected argument type 'String'}}
149149

150150
@available(*, unavailable, message: "call the 'map()' method on the sequence")
151-
public func myMap<C : Collection, T>(
151+
public func myMap<C : Collection, T>( // expected-note {{'myMap' has been explicitly marked unavailable here}}
152152
_ source: C, _ transform: (C.Iterator.Element) -> T
153153
) -> [T] {
154154
fatalError("unavailable function can't be called")
@@ -161,7 +161,7 @@ public func myMap<T, U>(_ x: T?, _ f: (T) -> U) -> U? {
161161

162162
// <rdar://problem/20142523>
163163
func rdar20142523() {
164-
myMap(0..<10, { x in // expected-error{{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{21-21=-> <#Result#> }} {{educational-notes=complex-closure-inference}}
164+
_ = myMap(0..<10, { x in // expected-error {{'myMap' is unavailable: call the 'map()' method on the sequence}}
165165
()
166166
return x
167167
})

test/Constraints/members.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ func rdar50679161() {
595595

596596
func foo() {
597597
_ = { () -> Void in
598+
// Missing `.self` or `init` is not diagnosed here because there are errors in
599+
// `if let` statement and `MiscDiagnostics` only run if the body is completely valid.
598600
var foo = S
599-
// expected-error@-1 {{expected member name or constructor call after type name}}
600-
// expected-note@-2 {{add arguments after the type to construct a value of the type}}
601-
// expected-note@-3 {{use '.self' to reference the type object}}
601+
602602
if let v = Int?(1) {
603603
var _ = Q(
604604
a: v + foo.w,
@@ -610,6 +610,14 @@ func rdar50679161() {
610610
)
611611
}
612612
}
613+
614+
_ = { () -> Void in
615+
var foo = S
616+
// expected-error@-1 {{expected member name or constructor call after type name}}
617+
// expected-note@-2 {{add arguments after the type to construct a value of the type}}
618+
// expected-note@-3 {{use '.self' to reference the type object}}
619+
print(foo)
620+
}
613621
}
614622
}
615623

test/Constraints/patterns.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ func good(_ a: A<EE>) -> Int {
230230
}
231231

232232
func bad(_ a: A<EE>) {
233-
a.map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}}
233+
let _ = a.map {
234234
let _: EE = $0
235235
return 1
236236
}
237237
}
238238

239239
func ugly(_ a: A<EE>) {
240-
a.map { // expected-error {{cannot infer return type for closure with multiple statements; add explicit type to disambiguate}} {{none}}
240+
let _ = a.map {
241241
switch $0 {
242242
case .A:
243243
return 1

test/Constraints/rdar46544601.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func crash(_ p: P, payload: [UInt8]) throws {
2626
p.foo(arr: arr, data: []).and(result: (id, arr))
2727
}.then { args0 in
2828
let (parentID, args1) = args0
29-
p.bar(root: parentID, from: p).and(args1)
29+
p.bar(root: parentID, from: p).and(result: args1)
3030
}.whenFailure { _ in }
3131
}

test/Constraints/rdar65320500.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ test_builder {
3131
test_builder {
3232
test(doesntExist()) // expected-error {{cannot find 'doesntExist' in scope}}
3333

34-
if let result = doesntExist() {
34+
if let result = doesntExist() { // expected-error {{cannot find 'doesntExist' in scope}}
3535
}
3636

37-
if bar = test(42) {}
37+
if bar = test(42) {} // expected-error {{cannot find 'bar' in scope}}
3838

39-
let foo = bar()
39+
let foo = bar() // expected-error {{cannot find 'bar' in scope}}
4040

41-
switch (doesntExist()) {
41+
switch (doesntExist()) { // expected-error {{cannot find 'doesntExist' in scope}}
4242
}
4343
}

test/Constraints/result_builder_diags.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf
7878
static func buildDo<T>(_ value: T) -> T { return value }
7979
}
8080

81-
func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) {
81+
func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) { // expected-note {{in call to function 'tuplify(_:body:)'}}
8282
print(body(cond))
8383
}
8484

@@ -309,12 +309,13 @@ struct MyTuplifiedStruct {
309309

310310
func test_invalid_return_type_in_body() {
311311
tuplify(true) { _ -> (Void, Int) in
312+
// If there is a `return` in the body result builder attribute is dropped, so nested `tuplify(false)`
313+
// is correct (type-check is successful) with multi-statement closure inference enabled.
312314
tuplify(false) { condition in
313315
if condition {
314-
return 42 // expected-error {{cannot use explicit 'return' statement in the body of result builder 'TupleBuilder'}}
315-
// expected-note@-1 {{remove 'return' statements to apply the result builder}} {{9-16=}}
316+
return 42
316317
} else {
317-
1
318+
1 // expected-warning {{integer literal is unused}}
318319
}
319320
}
320321

@@ -482,7 +483,7 @@ struct TestConstraintGenerationErrors {
482483
func buildTupleClosure() {
483484
tuplify(true) { _ in
484485
let a = nothing // expected-error {{cannot find 'nothing' in scope}}
485-
String(nothing)
486+
String(nothing) // expected-error {{cannot find 'nothing' in scope}}
486487
}
487488
}
488489
}
@@ -523,7 +524,7 @@ enum E3 {
523524
}
524525

525526
func testCaseMutabilityMismatches(e: E3) {
526-
tuplify(true) { c in
527+
tuplify(true) { c in // expected-error {{generic parameter 'T' could not be inferred}}
527528
"testSwitch"
528529
switch e {
529530
case .a(let x, var y),

test/Constraints/tuple.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ extension r25271859 {
218218
func map<U>(f: (T) -> U) -> r25271859<U> {
219219
}
220220

221-
func andThen<U>(f: (T) -> r25271859<U>) { // expected-note {{in call to function 'andThen(f:)'}}
221+
func andThen<U>(f: (T) -> r25271859<U>) {
222222
}
223223
}
224224

225225
func f(a : r25271859<(Float, Int)>) {
226-
a.map { $0.0 } // expected-error {{generic parameter 'U' could not be inferred}} (This is related to how solver is setup with multiple statements)
226+
a.map { $0.0 }
227227
.andThen { _ in
228-
print("hello") // comment this out and it runs, leave any form of print in and it doesn't
228+
print("hello")
229229
return r25271859<String>()
230230
}
231231
}

test/Constraints/tuple_arguments.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,25 +1407,41 @@ func processArrayOfFunctions(f1: [((Bool, Bool)) -> ()],
14071407
}
14081408

14091409
f2.forEach { block in
1410-
// expected-note@-1 2{{'block' declared here}}
1410+
// expected-note@-1 {{'block' declared here}}
14111411
block(p) // expected-error {{parameter 'block' expects 2 separate arguments}}
1412+
}
1413+
1414+
f2.forEach { block in
1415+
// expected-note@-1 {{'block' declared here}}
14121416
block((c, c)) // expected-error {{parameter 'block' expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}} {{11-12=}} {{16-17=}}
14131417
block(c, c)
14141418
}
14151419

1420+
f2.forEach { block in
1421+
block(c, c)
1422+
}
1423+
14161424
f2.forEach { (block: ((Bool, Bool)) -> ()) in
14171425
// expected-error@-1 {{cannot convert value of type '(((Bool, Bool)) -> ()) -> Void' to expected argument type '(@escaping (Bool, Bool) -> ()) throws -> Void'}}
14181426
block(p)
14191427
block((c, c))
1420-
block(c, c)
1428+
block(c, c) // expected-error {{parameter 'block' expects a single parameter of type '(Bool, Bool)'}}
14211429
}
14221430

14231431
f2.forEach { (block: (Bool, Bool) -> ()) in
1424-
// expected-note@-1 2{{'block' declared here}}
1432+
// expected-note@-1 {{'block' declared here}}
14251433
block(p) // expected-error {{parameter 'block' expects 2 separate arguments}}
1434+
}
1435+
1436+
f2.forEach { (block: (Bool, Bool) -> ()) in
1437+
// expected-note@-1 {{'block' declared here}}
14261438
block((c, c)) // expected-error {{parameter 'block' expects 2 separate arguments; remove extra parentheses to change tuple into separate arguments}} {{11-12=}} {{16-17=}}
14271439
block(c, c)
14281440
}
1441+
1442+
f2.forEach { (block: (Bool, Bool) -> ()) in
1443+
block(c, c)
1444+
}
14291445
}
14301446

14311447
// expected-error@+1 {{cannot create a single-element tuple with an element label}}

test/Constraints/without_actually_escaping.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func escapeX(_ xx: (Int) -> Int, _ value: Int) { // expected-note* {{non-escapin
1010
withoutActuallyEscaping(xx) { escapableXX in
1111
x = xx // expected-error{{non-escaping parameter}}
1212
x = escapableXX
13-
x = xx // expected-error{{non-escaping parameter}}
13+
x = xx
1414

1515
_ = x(value)
1616
_ = xx(value)

0 commit comments

Comments
 (0)