Skip to content

Commit 3d8493b

Browse files
committed
Sema: Also diagnose availability inside keypath index expressions
1 parent d08f6ff commit 3d8493b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,7 @@ class AvailabilityWalker : public ASTWalker {
23072307
}
23082308
}
23092309
if (auto KP = dyn_cast<KeyPathExpr>(E)) {
2310-
walkKeyPath(KP);
2311-
return skipChildren();
2310+
maybeDiagKeyPath(KP);
23122311
}
23132312
if (auto A = dyn_cast<AssignExpr>(E)) {
23142313
walkAssignExpr(A);
@@ -2406,7 +2405,7 @@ class AvailabilityWalker : public ASTWalker {
24062405

24072406
/// Walk a keypath expression, checking all of its components for
24082407
/// availability.
2409-
void walkKeyPath(KeyPathExpr *KP) {
2408+
void maybeDiagKeyPath(KeyPathExpr *KP) {
24102409
for (auto &component : KP->getComponents()) {
24112410
switch (component.getKind()) {
24122411
case KeyPathExpr::Component::Kind::Property:

test/expr/unary/keypath/keypath.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct Deprecated {
6262
subscript(x: Sub) -> Int { get { } set { } }
6363
}
6464

65+
@available(*, deprecated)
66+
func getDeprecatedSub() -> Sub {
67+
return Sub()
68+
}
69+
6570
extension Array where Element == A {
6671
var property: Prop { fatalError() }
6772
}
@@ -202,6 +207,8 @@ func testKeyPath(sub: Sub, optSub: OptSub,
202207

203208
let _ = \Deprecated.deprecatedProperty // expected-warning {{'deprecatedProperty' is deprecated}}
204209
let _ = \Deprecated.[sub] // expected-warning {{'subscript' is deprecated}}
210+
211+
let _ = \A.[getDeprecatedSub()] // expected-warning {{'getDeprecatedSub()' is deprecated}}
205212
}
206213

207214
func testKeyPathInGenericContext<H: Hashable, X>(hashable: H, anything: X) {

0 commit comments

Comments
 (0)