Skip to content

Commit 82e4c50

Browse files
committed
Fix a NULL pointer dereference and update test cases.
1 parent 9f2546b commit 82e4c50

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5786,7 +5786,7 @@ Expr *ExprRewriter::coerceCallArguments(
57865786
// Warn if there was a recent change in trailing closure binding semantics
57875787
// that might have lead to a silent change in behavior.
57885788
maybeWarnAboutTrailingClosureBindingChange(
5789-
callee, apply->getFn(), arg, args, params, paramInfo,
5789+
callee, apply ? apply->getFn() : nullptr, arg, args, params, paramInfo,
57905790
unlabeledTrailingClosureIndex, parameterBindings);
57915791

57925792
SourceLoc lParenLoc, rParenLoc;

test/Parse/multiple_trailing_closures.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ func bar(_ s: S) {
6868
}
6969
}
7070

71-
func multiple_trailing_with_defaults(
71+
func multiple_trailing_with_defaults( // expected-note{{contains defaulted closure parameters 'animations' and 'completion'}}
7272
duration: Int,
7373
animations: (() -> Void)? = nil,
7474
completion: (() -> Void)? = nil) {}
7575

76-
multiple_trailing_with_defaults(duration: 42) {}
76+
multiple_trailing_with_defaults(duration: 42) {} // expected-warning{{unlabeled trailing closure argument matches}}
77+
// expected-note@-1{{'completion' to retain}}
78+
// expected-note@-2{{'animations' to silence this}}
7779

7880
multiple_trailing_with_defaults(duration: 42) {} completion: {}
7981

test/expr/closure/trailing.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ func takeFunc(_ f: (Int) -> Int) -> Int {}
55
func takeValueAndFunc(_ value: Int, _ f: (Int) -> Int) {}
66
func takeTwoFuncs(_ f: (Int) -> Int, _ g: (Int) -> Int) {}
77
func takeFuncWithDefault(f : ((Int) -> Int)? = nil) {}
8-
func takeTwoFuncsWithDefaults(f1 : ((Int) -> Int)? = nil, f2 : ((String) -> String)? = nil) {}
8+
func takeTwoFuncsWithDefaults(f1 : ((Int) -> Int)? = nil, f2 : ((String) -> String)? = nil) {} // expected-note{{contains defaulted closure parameters 'f1' and 'f2'}}
99

1010
struct X {
1111
func takeFunc(_ f: (Int) -> Int) {}
@@ -94,8 +94,6 @@ var c3 = C().map // expected-note{{callee is here}}
9494
func multiTrailingClosure(_ a : () -> (), b : () -> ()) { // expected-note {{'multiTrailingClosure(_:b:)' declared here}}
9595
multiTrailingClosure({}) {} // ok
9696
multiTrailingClosure {} {} // expected-error {{missing argument for parameter 'b' in call}} expected-error {{consecutive statements on a line must be separated by ';'}} {{26-26=;}} expected-error {{closure expression is unused}} expected-note{{did you mean to use a 'do' statement?}} {{27-27=do }}
97-
98-
9997
}
10098

10199
func labeledArgumentAndTrailingClosure() {
@@ -108,7 +106,8 @@ func labeledArgumentAndTrailingClosure() {
108106

109107
// Trailing closure binds to first parameter.
110108
takeTwoFuncsWithDefaults { "Hello, " + $0 } // expected-error{{cannot convert value of type 'String' to expected argument type 'Int'}}
111-
takeTwoFuncsWithDefaults { $0 + 1 }
109+
takeTwoFuncsWithDefaults { $0 + 1 } // expected-warning{{rather than}}
110+
// expected-note@-1 2{{label the argument}}
112111
takeTwoFuncsWithDefaults(f1: {$0 + 1 })
113112
}
114113

test/expr/postfix/call/forward_trailing_closure.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-typecheck-verify-swift -disable-fuzzy-forward-scan-trailing-closure-matching
22

3-
func forwardMatch1(
3+
func forwardMatch1( // expected-note 5 {{contains defaulted}}
44
a: Int = 0, b: Int = 17, closure1: (Int) -> Int = { $0 }, c: Int = 42,
55
numbers: Int..., closure2: ((Double) -> Double)? = nil,
66
closure3: (String) -> String = { $0 + "!" }
@@ -11,24 +11,29 @@ func testForwardMatch1(i: Int, d: Double, s: String) {
1111
forwardMatch1()
1212

1313
// Matching closure1
14-
forwardMatch1 { _ in i }
14+
forwardMatch1 { _ in i } // expected-warning{{rather than}}
15+
// expected-note@-1 2{{label the argument}}
1516
forwardMatch1 { _ in i } closure2: { d + $0 }
1617
forwardMatch1 { _ in i } closure2: { d + $0 } closure3: { $0 + ", " + s + "!" }
1718
forwardMatch1 { _ in i } closure3: { $0 + ", " + s + "!" }
1819

19-
forwardMatch1(a: 5) { $0 + i }
20+
forwardMatch1(a: 5) { $0 + i } // expected-warning{{rather than}}
21+
// expected-note@-1 2{{label the argument}}
2022
forwardMatch1(a: 5) { $0 + i } closure2: { d + $0 }
2123
forwardMatch1(a: 5) { $0 + i } closure2: { d + $0 } closure3: { $0 + ", " + s + "!" }
2224
forwardMatch1(a: 5) { $0 + i } closure3: { $0 + ", " + s + "!" }
2325

24-
forwardMatch1(b: 1) { $0 + i }
26+
forwardMatch1(b: 1) { $0 + i } // expected-warning{{rather than}}
27+
// expected-note@-1 2{{label the argument}}
2528
forwardMatch1(b: 1) { $0 + i } closure2: { d + $0 }
2629
forwardMatch1(b: 1) { $0 + i } closure2: { d + $0 } closure3: { $0 + ", " + s + "!" }
2730
forwardMatch1(b: 1) { $0 + i } closure3: { $0 + ", " + s + "!" }
2831

2932
// Matching closure2
30-
forwardMatch1(closure1: { $0 + i }) { d + $0 }
31-
forwardMatch1(closure1: { $0 + i }, numbers: 1, 2, 3) { d + $0 }
33+
forwardMatch1(closure1: { $0 + i }) { d + $0 } // expected-warning{{rather than}}
34+
// expected-note@-1 2{{label the argument}}
35+
forwardMatch1(closure1: { $0 + i }, numbers: 1, 2, 3) { d + $0 } // expected-warning{{rather than}}
36+
// expected-note@-1 2{{label the argument}}
3237
forwardMatch1(closure1: { $0 + i }, numbers: 1, 2, 3) { d + $0 } closure3: { $0 + ", " + s + "!" }
3338

3439
// Matching closure3

0 commit comments

Comments
 (0)