Skip to content

Commit ae79b0d

Browse files
committed
[CSApply] Always use String type for ObjC interop key path
If it's possible to build an Objective-C key path for key path expression make sure that its implicitly generated string literal expression has a `String` type. Resolves: rdar://problem/57356196
1 parent 0174f5d commit ae79b0d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4312,7 +4312,7 @@ namespace {
43124312
StringRef(stringCopy, compatStringBuf.size()),
43134313
SourceRange(),
43144314
/*implicit*/ true);
4315-
cs.setType(stringExpr, cs.getType(E));
4315+
cs.setType(stringExpr, TypeChecker::getStringType(cs.getASTContext()));
43164316
E->setObjCStringLiteralExpr(stringExpr);
43174317
}
43184318
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -verify
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc class A : NSObject {
7+
@objc var x: Int = 42
8+
}
9+
10+
@propertyWrapper
11+
struct Attr<V> {
12+
var wrappedValue: V {
13+
get { fatalError() }
14+
}
15+
16+
init(wrappedValue: V, key: KeyPath<A, V>) {}
17+
}
18+
19+
class B {
20+
@Attr(key: \.x) var y: Int = 0 // Ok
21+
}

0 commit comments

Comments
 (0)