Skip to content

Commit ba8e00d

Browse files
committed
[cxx-interop] Add fix-it for foreign reference types.
1 parent 41f01e3 commit ba8e00d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4402,12 +4402,24 @@ ClangImporter::Implementation::importDiagnosticTargetFromLookupTableEntry(
44024402
"MacroInfo or ModuleMacro pointer");
44034403
}
44044404

4405+
static void diagnoseForeignReferenceTypeFixit(ClangImporter::Implementation &Impl,
4406+
HeaderLoc loc, Diagnostic diag) {
4407+
auto importedLoc =
4408+
Impl.SwiftContext.getClangModuleLoader()->importSourceLocation(loc.clangLoc);
4409+
Impl.diagnose(loc, diag)
4410+
.fixItInsert(importedLoc, "SWIFT_REFERENCE_TYPE(<#retain#>, <#release#>) ");
4411+
}
4412+
44054413
bool ClangImporter::Implementation::emitDiagnosticsForTarget(
44064414
ImportDiagnosticTarget target, clang::SourceLocation fallbackLoc) {
44074415
for (auto it = ImportDiagnostics[target].rbegin();
44084416
it != ImportDiagnostics[target].rend(); ++it) {
44094417
HeaderLoc loc = HeaderLoc(it->loc.isValid() ? it->loc : fallbackLoc);
4410-
diagnose(loc, it->diag);
4418+
if (it->diag.getID() == diag::record_not_automatically_importable.ID) {
4419+
diagnoseForeignReferenceTypeFixit(*this, loc, it->diag);
4420+
} else {
4421+
diagnose(loc, it->diag);
4422+
}
44114423
}
44124424
return ImportDiagnostics[target].size();
44134425
}

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,10 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
917917
/// interface. Use this to diagnose issues with declarations that are not
918918
/// imported or that are not reflected in a generated interface.
919919
template<typename ...Args>
920-
void diagnose(HeaderLoc loc, Args &&...args) {
920+
InFlightDiagnostic diagnose(HeaderLoc loc, Args &&...args) {
921921
// If we're in the middle of pretty-printing, suppress diagnostics.
922922
if (SwiftContext.Diags.isPrettyPrintingDecl()) {
923-
return;
923+
return InFlightDiagnostic();
924924
}
925925

926926
auto swiftLoc = loc.fallbackLoc;
@@ -932,7 +932,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
932932
loc.clangLoc);
933933
}
934934

935-
SwiftContext.Diags.diagnose(swiftLoc, std::forward<Args>(args)...);
935+
return SwiftContext.Diags.diagnose(swiftLoc, std::forward<Args>(args)...);
936936
}
937937

938938
void addImportDiagnostic(

0 commit comments

Comments
 (0)