@@ -229,6 +229,9 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
229229};
230230
231231static ValueDecl* getReferencedDecl (Expr *E) {
232+ // Get the syntactic expression out of an implicit expression.
233+ if (auto *ICE = dyn_cast<ImplicitConversionExpr>(E))
234+ E = ICE->getSyntacticSubExpr ();
232235 if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
233236 return DRE->getDecl ();
234237 } else if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
@@ -309,7 +312,15 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
309312 APIDiffMigratorPass (EditorAdapter &Editor, SourceFile *SF,
310313 const MigratorOptions &Opts):
311314 ASTMigratorPass (Editor, SF, Opts),
312- FileEndLoc (SM.getRangeForBuffer(BufferID).getEnd()) {}
315+ FileEndLoc (SM.getRangeForBuffer(BufferID).getEnd()) {
316+ SmallVector<Decl*, 16 > TopDecls;
317+ SF->getTopLevelDecls (TopDecls);
318+ for (auto *D: TopDecls) {
319+ if (auto *FD = dyn_cast<FuncDecl>(D)) {
320+ InsertedFunctions.insert (FD->getBaseName ().getIdentifier ().str ());
321+ }
322+ }
323+ }
313324
314325 void run () {
315326 if (Opts.APIDigesterDataStorePaths .empty ())
@@ -675,6 +686,11 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
675686 }
676687 }
677688
689+ void replaceExpr (Expr* E, StringRef Text) {
690+ Editor.replace (CharSourceRange (SM, E->getStartLoc (),
691+ Lexer::getLocForEndOfToken (SM, E->getEndLoc ())), Text);
692+ }
693+
678694 bool wrapAttributeReference (Expr* Reference, Expr* WrapperTarget,
679695 bool FromString) {
680696 auto *RD = getReferencedDecl (Reference);
@@ -699,18 +715,26 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
699715 Editor.insert (WrapperTarget->getStartLoc (), (Twine (Func) + " (" ).str ());
700716 Editor.insertAfterToken (WrapperTarget->getEndLoc (), " )" );
701717 if (!Rename.empty ()) {
702- auto Range = CharSourceRange (SM, Reference->getStartLoc (),
703- Lexer::getLocForEndOfToken (SM, Reference->getEndLoc ()));
704- Editor.replace (Range, Rename);
718+ replaceExpr (Reference, Rename);
705719 }
706720 return true ;
707721 }
708722
709723 bool handleAssignDestMigration (Expr *E) {
724+ Editor.disableCache ();
725+ SWIFT_DEFER { Editor.enableCache (); };
710726 auto *ASE = dyn_cast<AssignExpr>(E);
711727 if (!ASE || !ASE->getDest () || !ASE->getSrc ())
712728 return false ;
713- return wrapAttributeReference (ASE->getDest (), ASE->getSrc (), true );
729+ auto *Dest = ASE->getDest ();
730+ auto Src = ASE->getSrc ();
731+ if (wrapAttributeReference (Dest, Src, true )) {
732+ // We should handle the assignment source here since we won't visit
733+ // the children with present changes.
734+ handleAttributeReference (Src);
735+ return true ;
736+ }
737+ return false ;
714738 }
715739
716740 bool handleAttributeReference (Expr *E) {
0 commit comments