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

Code before:
    case DisallowedOriginKind::SPILocal:
      return DiagnosticBehavior::Ignore;
    case DisallowedOriginKind::MissingImport:
    case DisallowedOriginKind::InternalBridgingHeaderImport:
    case DisallowedOriginKind::ImplementationOnly:
    case DisallowedOriginKind::FragileCxxAPI:
    case DisallowedOriginKind::ImplementationOnlyMemoryLayout:
      break;
    }
  }

  // Allow references to hidden dependencies from `@c/objc @implementation`
  // decl signatures.
  if (getDeclContext()->isInObjCImplementationContext()) {
    switch (originKind) {
    case DisallowedOriginKind::None:
    case DisallowedOriginKind::NonPublicImport:
    case DisallowedOriginKind::InternalBridgingHeaderImport:
    case DisallowedOriginKind::ImplementationOnly:
      return DiagnosticBehavior::Ignore;
    case DisallowedOriginKind::SPIOnly:
    case DisallowedOriginKind::SPIImported:
    case DisallowedOriginKind::SPILocal:
    case DisallowedOriginKind::MissingImport:
    case DisallowedOriginKind::FragileCxxAPI:
    case DisallowedOriginKind::ImplementationOnlyMemoryLayout:
      break;
    }
  }

  // Exportability checking for non-library-evolution was introduced late,
  // downgrade errors to warnings by default.
  auto &ctx = DC->getASTContext();
  if (getExportedLevel() == ExportedLevel::ImplicitlyExported &&
      originKind != DisallowedOriginKind::ImplementationOnlyMemoryLayout &&
      !ctx.LangOpts.hasFeature(Feature::CheckImplementationOnly) &&
      !ctx.isLanguageModeAtLeast(7))
    return DiagnosticBehavior::Warning;

  return DiagnosticBehavior::Error;
}

std::optional<ExportabilityReason>
ExportContext::getExportabilityReason() const {
  if (Exported)
    return ExportabilityReason(Reason);
  return std::nullopt;
}

static bool shouldAllowReferenceToUnavailableInSwiftDeclaration(
    const Decl *D, const ExportContext &where) {

Review comment (suggestion):
Should these other kinds be ignored too? If implementations don't have any API surface of their own and rely entirely on their headers for visibility, none of these ought to create new problems that aren't already there in the headers themselves.

Code after:
    case DisallowedOriginKind::SPILocal:
      return DiagnosticBehavior::Ignore;
    case DisallowedOriginKind::MissingImport:
    case DisallowedOriginKind::InternalBridgingHeaderImport:
    case DisallowedOriginKind::ImplementationOnly:
    case DisallowedOriginKind::FragileCxxAPI:
    case DisallowedOriginKind::ImplementationOnlyMemoryLayout:
      break;
    }
  }

  // Allow references to hidden dependencies from `@c/objc @implementation`
  // decl signatures.
  if (getDeclContext()->isInObjCImplementationContext()) {
    switch (originKind) {
    case DisallowedOriginKind::None:
    case DisallowedOriginKind::NonPublicImport:
    case DisallowedOriginKind::InternalBridgingHeaderImport:
    case DisallowedOriginKind::ImplementationOnly:
    case DisallowedOriginKind::SPIOnly:
      return DiagnosticBehavior::Ignore;
    case DisallowedOriginKind::SPIImported:
    case DisallowedOriginKind::SPILocal:
    case DisallowedOriginKind::MissingImport:
    case DisallowedOriginKind::FragileCxxAPI:
    case DisallowedOriginKind::ImplementationOnlyMemoryLayout:
      break;
    }
  }

  // Exportability checking for non-library-evolution was introduced late,
  // downgrade errors to warnings by default.
  auto &ctx = DC->getASTContext();
  if (getExportedLevel() == ExportedLevel::ImplicitlyExported &&
      originKind != DisallowedOriginKind::ImplementationOnlyMemoryLayout &&
      !ctx.LangOpts.hasFeature(Feature::CheckImplementationOnly) &&
      !ctx.isLanguageModeAtLeast(7))
    return DiagnosticBehavior::Warning;

  return DiagnosticBehavior::Error;
}

std::optional<ExportabilityReason>
ExportContext::getExportabilityReason() const {
  if (Exported)
    return ExportabilityReason(Reason);
  return std::nullopt;
}

static bool shouldAllowReferenceToUnavailableInSwiftDeclaration(
    const Decl *D, const ExportContext &where) {