Skip to content

Commit 7552cf9

Browse files
committed
Maintain module name location in UnboundImport (again).
The change to add the `import` keyword location to AttributedImport also removed the module name location in UnboundImport. However, we want to keep both locations, for different diagnostic reasons, so reinstate the module name location.
1 parent ceedb01 commit 7552cf9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct UnboundImport {
5656
/// determine the behavior expected for this import.
5757
AttributedImport<UnloadedImportedModule> import;
5858

59+
/// The source location to use when diagnosing errors for this import.
60+
SourceLoc importLoc;
61+
5962
/// If this UnboundImport directly represents an ImportDecl, contains the
6063
/// ImportDecl it represents. This should only be used for diagnostics and
6164
/// for updating the AST; if you want to read information about the import,
@@ -511,7 +514,7 @@ void ImportResolver::addImplicitImports() {
511514
}
512515

513516
UnboundImport::UnboundImport(AttributedImport<UnloadedImportedModule> implicit)
514-
: import(implicit),
517+
: import(implicit), importLoc(),
515518
importOrUnderlyingModuleDecl(static_cast<ImportDecl *>(nullptr)) {}
516519

517520
//===----------------------------------------------------------------------===//
@@ -522,7 +525,7 @@ UnboundImport::UnboundImport(AttributedImport<UnloadedImportedModule> implicit)
522525
UnboundImport::UnboundImport(ImportDecl *ID)
523526
: import(UnloadedImportedModule(ID->getImportPath(), ID->getImportKind()),
524527
ID->getStartLoc(), {}),
525-
importOrUnderlyingModuleDecl(ID)
528+
importLoc(ID->getLoc()), importOrUnderlyingModuleDecl(ID)
526529
{
527530
if (ID->isExported())
528531
import.options |= ImportFlags::Exported;
@@ -569,11 +572,10 @@ bool UnboundImport::checkNotTautological(const SourceFile &SF) {
569572

570573
StringRef filename = llvm::sys::path::filename(SF.getFilename());
571574
if (filename.empty())
572-
ctx.Diags.diagnose(import.importLoc, diag::sema_import_current_module,
575+
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module,
573576
modulePath.front().Item);
574577
else
575-
ctx.Diags.diagnose(import.importLoc,
576-
diag::sema_import_current_module_with_file,
578+
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module_with_file,
577579
filename, modulePath.front().Item);
578580

579581
return false;
@@ -583,7 +585,7 @@ bool UnboundImport::checkModuleLoaded(ModuleDecl *M, SourceFile &SF) {
583585
if (M)
584586
return true;
585587

586-
diagnoseNoSuchModule(SF.getParentModule(), import.importLoc,
588+
diagnoseNoSuchModule(SF.getParentModule(), importLoc,
587589
import.module.getModulePath(), /*nonfatalInREPL=*/true);
588590
return false;
589591
}
@@ -962,9 +964,9 @@ UnboundImport::UnboundImport(
962964
ASTContext &ctx, const UnboundImport &base, Identifier overlayName,
963965
const AttributedImport<ImportedModule> &declaringImport,
964966
const AttributedImport<ImportedModule> &bystandingImport)
965-
: import(makeUnimportedCrossImportOverlay(
966-
ctx, overlayName, base, declaringImport),
967-
base.import.importLoc, {}),
967+
: import(makeUnimportedCrossImportOverlay(ctx, overlayName, base,
968+
declaringImport), {}),
969+
importLoc(base.importLoc),
968970
importOrUnderlyingModuleDecl(declaringImport.module.importedModule)
969971
{
970972
// A cross-import is never private or testable, and never comes from a private
@@ -1098,16 +1100,15 @@ void ImportResolver::findCrossImports(
10981100
// Find modules we need to import.
10991101
SmallVector<Identifier, 4> names;
11001102
declaringImport.module.importedModule->findDeclaredCrossImportOverlays(
1101-
bystandingImport.module.importedModule->getName(), names,
1102-
I.import.importLoc);
1103+
bystandingImport.module.importedModule->getName(), names, I.importLoc);
11031104

11041105
// If we're diagnosing cases where we cross-import in both directions, get the
11051106
// inverse list. Otherwise, leave the list empty.
11061107
SmallVector<Identifier, 4> oppositeNames;
11071108
if (shouldDiagnoseRedundantCrossImports)
11081109
bystandingImport.module.importedModule->findDeclaredCrossImportOverlays(
11091110
declaringImport.module.importedModule->getName(), oppositeNames,
1110-
I.import.importLoc);
1111+
I.importLoc);
11111112

11121113
if (ctx.Stats && !names.empty())
11131114
++ctx.Stats->getFrontendCounters().NumCrossImportsFound;
@@ -1124,14 +1125,13 @@ void ImportResolver::findCrossImports(
11241125
declaringImport, bystandingImport);
11251126

11261127
if (llvm::is_contained(oppositeNames, name))
1127-
ctx.Diags.diagnose(I.import.importLoc,
1128-
diag::cross_imported_by_both_modules,
1128+
ctx.Diags.diagnose(I.importLoc, diag::cross_imported_by_both_modules,
11291129
declaringImport.module.importedModule->getName(),
11301130
bystandingImport.module.importedModule->getName(),
11311131
name);
11321132

11331133
if (ctx.LangOpts.EnableCrossImportRemarks)
1134-
ctx.Diags.diagnose(I.import.importLoc, diag::cross_import_added,
1134+
ctx.Diags.diagnose(I.importLoc, diag::cross_import_added,
11351135
declaringImport.module.importedModule->getName(),
11361136
bystandingImport.module.importedModule->getName(),
11371137
name);

0 commit comments

Comments
 (0)