Repository: apple/swift
File: lib/Sema/MiscDiagnostics.cpp (C++)

Code before:
  const_cast<Expr *>(E)->walk(Walker);
}

// Verifies that references to members are valid under the restrictions of the
// MemberImportVisibility feature.
static void diagnoseMissingMemberImports(const Expr *E, const DeclContext *DC) {
  class DiagnoseWalker : public BaseDiagnosticWalker {
    const DeclContext *dc;

  public:
    DiagnoseWalker(const DeclContext *dc) : dc(dc) {}

    PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
      if (auto declRef = E->getReferencedDecl()) {
        bool downgradeToWarning = false;
        auto *decl = declRef.getDecl();

        // If this is an implicit reference to `make{Async}Iterator`
        // or `next` methods, let's produce a warning instead of an
        // error to maintain source compatibility since it wasn't
        // diagnosed before.
        if (E->isImplicit() && decl->isInstanceMember()) {
          auto &ctx = decl->getASTContext();
          auto name = decl->getBaseName();
          downgradeToWarning =
              !ctx.isAtLeastFutureMajorLanguageMode() &&
              (name == ctx.Id_makeIterator ||
               name == ctx.Id_makeAsyncIterator || name == ctx.Id_next);
        }

        checkDecl(decl, E->getLoc(), downgradeToWarning);
      }

      if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
        for (const auto &component : KPE->getComponents()) {
          if (component.hasDeclRef())
            checkDecl(component.getDeclRef().getDecl(), component.getLoc(),
                      /*downgradeToWarning=*/true);
        }
      }

      return Action::Continue(E);
    }

    void checkDecl(const ValueDecl *decl, SourceLoc loc,
                   bool downgradeToWarning = false) {
      // Only diagnose uses of members.
      if (!decl->getDeclContext()->isTypeContext())
        return;

      if (!dc->isDeclImported(decl))

Review comment (suggestion):
`isAtLeastFutureMajorLanguageMode` was recently removed, you'll want to rebase on #86956 and use `isLanguageModeAtLeast(LanguageMode::future)` instead

Code after:
  const_cast<Expr *>(E)->walk(Walker);
}

// Verifies that references to members are valid under the restrictions of the
// MemberImportVisibility feature.
static void diagnoseMissingMemberImports(const Expr *E, const DeclContext *DC) {
  class DiagnoseWalker : public BaseDiagnosticWalker {
    const DeclContext *dc;

  public:
    DiagnoseWalker(const DeclContext *dc) : dc(dc) {}

    PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
      if (auto declRef = E->getReferencedDecl()) {
        bool downgradeToWarning = false;
        auto *decl = declRef.getDecl();

        // If this is an implicit reference to `make{Async}Iterator`
        // or `next` methods, let's produce a warning instead of an
        // error to maintain source compatibility since it wasn't
        // diagnosed before in closure contexts.
        if (E->isImplicit() && decl->isInstanceMember()) {
          auto &ctx = decl->getASTContext();
          auto name = decl->getBaseName();

          downgradeToWarning =
              !ctx.isLanguageModeAtLeast(LanguageMode::future) &&
              isInClosureContext() &&
              (name == ctx.Id_makeIterator ||
               name == ctx.Id_makeAsyncIterator || name == ctx.Id_next);
        }

        checkDecl(decl, E->getLoc(), downgradeToWarning);
      }

      if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
        for (const auto &component : KPE->getComponents()) {
          if (component.hasDeclRef())
            checkDecl(component.getDeclRef().getDecl(), component.getLoc(),
                      /*downgradeToWarning=*/true);
        }
      }

      return Action::Continue(E);
    }

    void checkDecl(const ValueDecl *decl, SourceLoc loc,
                   bool downgradeToWarning = false) {
      // Only diagnose uses of members.
      if (!decl->getDeclContext()->isTypeContext())
        return;