@@ -398,6 +398,26 @@ namespace {
398
398
return base.getOldType ();
399
399
}
400
400
401
+ // / Check whether it is possible to have an ObjC key path string for the keypath expression
402
+ // / and set the key path string, if yes
403
+ void checkAndSetObjCKeyPathString (KeyPathExpr *keyPath) {
404
+ if (cs.getASTContext ().LangOpts .EnableObjCInterop ) {
405
+ SmallString<64 > compatStringBuf;
406
+ if (buildObjCKeyPathString (keyPath, compatStringBuf)) {
407
+ auto stringCopy = cs.getASTContext ().AllocateCopy <char >(compatStringBuf.begin (),
408
+ compatStringBuf.end ());
409
+ auto stringExpr = new (cs.getASTContext ()) StringLiteralExpr (
410
+ StringRef (stringCopy, compatStringBuf.size ()),
411
+ SourceRange (),
412
+ /* implicit*/ true );
413
+ cs.setType (
414
+ stringExpr,
415
+ cs.getASTContext ().getStringDecl ()->getDeclaredInterfaceType ());
416
+ keyPath->setObjCStringLiteralExpr (stringExpr);
417
+ }
418
+ }
419
+ }
420
+
401
421
// Returns None if the AST does not contain enough information to recover
402
422
// substitutions; this is different from an Optional(SubstitutionMap()),
403
423
// indicating a valid call to a non-generic operator.
@@ -2041,6 +2061,11 @@ namespace {
2041
2061
keyPath->setParsedPath (componentExpr);
2042
2062
keyPath->resolveComponents (ctx, components);
2043
2063
cs.cacheExprTypes (keyPath);
2064
+
2065
+ // See whether there's an equivalent ObjC key path string we can produce
2066
+ // for interop purposes.
2067
+ checkAndSetObjCKeyPathString (keyPath);
2068
+
2044
2069
return keyPath;
2045
2070
}
2046
2071
@@ -4755,22 +4780,7 @@ namespace {
4755
4780
4756
4781
// See whether there's an equivalent ObjC key path string we can produce
4757
4782
// for interop purposes.
4758
- if (cs.getASTContext ().LangOpts .EnableObjCInterop ) {
4759
- SmallString<64 > compatStringBuf;
4760
- if (buildObjCKeyPathString (E, compatStringBuf)) {
4761
- auto stringCopy =
4762
- cs.getASTContext ().AllocateCopy <char >(compatStringBuf.begin (),
4763
- compatStringBuf.end ());
4764
- auto stringExpr = new (cs.getASTContext ()) StringLiteralExpr (
4765
- StringRef (stringCopy, compatStringBuf.size ()),
4766
- SourceRange (),
4767
- /* implicit*/ true );
4768
- cs.setType (
4769
- stringExpr,
4770
- cs.getASTContext ().getStringDecl ()->getDeclaredInterfaceType ());
4771
- E->setObjCStringLiteralExpr (stringExpr);
4772
- }
4773
- }
4783
+ checkAndSetObjCKeyPathString (E);
4774
4784
4775
4785
// The final component type ought to line up with the leaf type of the
4776
4786
// key path.
0 commit comments