Skip to content

Commit 4acb094

Browse files
committed
Fix a NULL pointer dereference and update test cases.
1 parent c667025 commit 4acb094

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

lib/Sema/CSApply.cpp

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

57295729
SourceLoc lParenLoc, rParenLoc;

test/Constraints/diagnostics.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,12 +1101,9 @@ func rdar17170728() {
11011101
// expected-error@-1 4 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
11021102
}
11031103

1104-
// expected-error@+4 {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
1105-
// expected-error@+3 {{missing argument label 'into:' in call}}
1106-
// expected-note@+2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
1107-
// expected-note@+1 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
11081104
let _ = [i, j, k].reduce(0 as Int?) {
1109-
// expected-error@-1 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
1105+
// expected-error@-1{{missing argument label 'into:' in call}}
1106+
// expected-error@-2{{cannot convert value of type 'Int?' to expected argument type}}
11101107
$0 && $1 ? $0 + $1 : ($0 ? $0 : ($1 ? $1 : nil))
11111108
// expected-error@-1 2 {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
11121109
// expected-error@-2 {{cannot convert value of type 'Bool' to expected argument type 'Int'}}

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)