Repository: apple/swift
File: lib/IDE/SourceEntityWalker.cpp (C++)

Code before:
      !isa<SubscriptExpr>(E) && !isa<KeyPathExpr>(E) && !isa<LiteralExpr>(E) &&
      !isa<CollectionExpr>(E) && E->isImplicit())
    return Action::Continue(E);

  if (auto LE = dyn_cast<LiteralExpr>(E)) {
    if (LE->getInitializer() &&
        !passReference(LE->getInitializer().getDecl(), LE->getType(), {},
                       LE->getSourceRange(),
                       ReferenceMetaData(SemaReferenceKind::DeclRef, OpAccess,
                                         /*isImplicit=*/true))) {
      return Action::Stop();
    }
    return Action::Continue(E);
  } else if (auto CE = dyn_cast<CollectionExpr>(E)) {
    if (CE->getInitializer() &&
        !passReference(CE->getInitializer().getDecl(), CE->getType(), {},
                       CE->getSourceRange(),
                       ReferenceMetaData(SemaReferenceKind::DeclRef, OpAccess,
                                         /*isImplicit=*/true))) {
      return Action::Stop();
    }
    return Action::Continue(E);
  } else if (auto *CE = dyn_cast<CallExpr>(E)) {
    // Handle CallExpr where the function reference is implicit
    // (e.g., appendInterpolation calls in string interpolation).
    // The implicit DeclRefExpr would normally be skipped, so we index it here.
    if (CE->getFn()->isImplicit()) {
      auto fnRef = ide::getReferencedDecl(CE->getFn());
      auto *D = fnRef.second.getDecl();
      // Skip constructors - they're handled via CtorRefs
      if (auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(D)) {
        if (!isa<ConstructorDecl>(FD)) {
          ReferenceMetaData data(SemaReferenceKind::DeclMemberRef, OpAccess);
          if (!passReference(FD, CE->getType(), CE->getLoc(),
                             CE->getSourceRange(), data))
            return Action::Stop();
        }
      }
    }
  } else if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
    if (auto *module = dyn_cast<ModuleDecl>(DRE->getDecl())) {
      if (!passReference(ModuleEntity(module),
                         {module->getName(), E->getLoc()}))
        return Action::Stop();
    } else if (!passReference(DRE->getDecl(), DRE->getType(),
                              DRE->getNameLoc(),
                      ReferenceMetaData(getReferenceKind(Parent.getAsExpr(), DRE),
                                        OpAccess))) {
      return Action::Stop();
    }
  } else if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {

Review comment (suggestion):
Rather than special-casing this for CallExprs I think it would make more sense to see if we could pass decl references for implicit DeclRefExprs and MemberRefExprs more generally, ensuring that we set the `isImplicit` bit on the `ReferenceMetaData`

Code after:
      return Action::Continue(E);
  }

  if (!isa<InOutExpr>(E) && !isa<LoadExpr>(E) && !isa<OpenExistentialExpr>(E) &&
      !isa<MakeTemporarilyEscapableExpr>(E) &&
      !isa<CollectionUpcastConversionExpr>(E) && !isa<OpaqueValueExpr>(E) &&
      !isa<SubscriptExpr>(E) && !isa<KeyPathExpr>(E) && !isa<LiteralExpr>(E) &&
      !isa<CollectionExpr>(E) && !isa<DeclRefExpr>(E) && !isa<MemberRefExpr>(E) &&
      E->isImplicit())
    return Action::Continue(E);

  if (auto LE = dyn_cast<LiteralExpr>(E)) {
    if (LE->getInitializer() &&
        !passReference(LE->getInitializer().getDecl(), LE->getType(), {},
                       LE->getSourceRange(),
                       ReferenceMetaData(SemaReferenceKind::DeclRef, OpAccess,
                                         /*isImplicit=*/true))) {
      return Action::Stop();
    }
    return Action::Continue(E);
  } else if (auto CE = dyn_cast<CollectionExpr>(E)) {
    if (CE->getInitializer() &&
        !passReference(CE->getInitializer().getDecl(), CE->getType(), {},
                       CE->getSourceRange(),
                       ReferenceMetaData(SemaReferenceKind::DeclRef, OpAccess,
                                         /*isImplicit=*/true))) {
      return Action::Stop();
    }
    return Action::Continue(E);
  } else if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
    if (auto *module = dyn_cast<ModuleDecl>(DRE->getDecl())) {
      if (!passReference(ModuleEntity(module),
                         {module->getName(), E->getLoc()}))
        return Action::Stop();
    } else if (!passReference(DRE->getDecl(), DRE->getType(),
                              DRE->getNameLoc(),
                      ReferenceMetaData(getReferenceKind(Parent.getAsExpr(), DRE),
                                        OpAccess, DRE->isImplicit()))) {
      return Action::Stop();
    }
  } else if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
    {
      // This could be made more accurate if the member is nonmutating,
      // or whatever.
      std::optional<AccessKind> NewOpAccess;
      if (OpAccess) {
        if (*OpAccess == AccessKind::Write)
          NewOpAccess = AccessKind::ReadWrite;
        else
          NewOpAccess = OpAccess;
      }