@@ -56,6 +56,9 @@ struct UnboundImport {
56
56
// / determine the behavior expected for this import.
57
57
AttributedImport<UnloadedImportedModule> import ;
58
58
59
+ // / The source location to use when diagnosing errors for this import.
60
+ SourceLoc importLoc;
61
+
59
62
// / If this UnboundImport directly represents an ImportDecl, contains the
60
63
// / ImportDecl it represents. This should only be used for diagnostics and
61
64
// / for updating the AST; if you want to read information about the import,
@@ -511,7 +514,7 @@ void ImportResolver::addImplicitImports() {
511
514
}
512
515
513
516
UnboundImport::UnboundImport (AttributedImport<UnloadedImportedModule> implicit)
514
- : import(implicit),
517
+ : import(implicit), importLoc(),
515
518
importOrUnderlyingModuleDecl(static_cast <ImportDecl *>(nullptr )) {}
516
519
517
520
// ===----------------------------------------------------------------------===//
@@ -522,7 +525,7 @@ UnboundImport::UnboundImport(AttributedImport<UnloadedImportedModule> implicit)
522
525
UnboundImport::UnboundImport (ImportDecl *ID)
523
526
: import(UnloadedImportedModule(ID->getImportPath (), ID->getImportKind()),
524
527
ID->getStartLoc(), {}),
525
- importOrUnderlyingModuleDecl(ID)
528
+ importLoc(ID-> getLoc ()), importOrUnderlyingModuleDecl(ID)
526
529
{
527
530
if (ID->isExported ())
528
531
import .options |= ImportFlags::Exported;
@@ -569,11 +572,10 @@ bool UnboundImport::checkNotTautological(const SourceFile &SF) {
569
572
570
573
StringRef filename = llvm::sys::path::filename (SF.getFilename ());
571
574
if (filename.empty ())
572
- ctx.Diags .diagnose (import . importLoc , diag::sema_import_current_module,
575
+ ctx.Diags .diagnose (importLoc, diag::sema_import_current_module,
573
576
modulePath.front ().Item );
574
577
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,
577
579
filename, modulePath.front ().Item );
578
580
579
581
return false ;
@@ -583,7 +585,7 @@ bool UnboundImport::checkModuleLoaded(ModuleDecl *M, SourceFile &SF) {
583
585
if (M)
584
586
return true ;
585
587
586
- diagnoseNoSuchModule (SF.getParentModule (), import . importLoc ,
588
+ diagnoseNoSuchModule (SF.getParentModule (), importLoc,
587
589
import .module .getModulePath (), /* nonfatalInREPL=*/ true );
588
590
return false ;
589
591
}
@@ -962,9 +964,9 @@ UnboundImport::UnboundImport(
962
964
ASTContext &ctx, const UnboundImport &base, Identifier overlayName,
963
965
const AttributedImport<ImportedModule> &declaringImport,
964
966
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),
968
970
importOrUnderlyingModuleDecl(declaringImport.module .importedModule)
969
971
{
970
972
// A cross-import is never private or testable, and never comes from a private
@@ -1098,16 +1100,15 @@ void ImportResolver::findCrossImports(
1098
1100
// Find modules we need to import.
1099
1101
SmallVector<Identifier, 4 > names;
1100
1102
declaringImport.module .importedModule ->findDeclaredCrossImportOverlays (
1101
- bystandingImport.module .importedModule ->getName (), names,
1102
- I.import .importLoc );
1103
+ bystandingImport.module .importedModule ->getName (), names, I.importLoc );
1103
1104
1104
1105
// If we're diagnosing cases where we cross-import in both directions, get the
1105
1106
// inverse list. Otherwise, leave the list empty.
1106
1107
SmallVector<Identifier, 4 > oppositeNames;
1107
1108
if (shouldDiagnoseRedundantCrossImports)
1108
1109
bystandingImport.module .importedModule ->findDeclaredCrossImportOverlays (
1109
1110
declaringImport.module .importedModule ->getName (), oppositeNames,
1110
- I.import . importLoc );
1111
+ I.importLoc );
1111
1112
1112
1113
if (ctx.Stats && !names.empty ())
1113
1114
++ctx.Stats ->getFrontendCounters ().NumCrossImportsFound ;
@@ -1124,14 +1125,13 @@ void ImportResolver::findCrossImports(
1124
1125
declaringImport, bystandingImport);
1125
1126
1126
1127
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,
1129
1129
declaringImport.module .importedModule ->getName (),
1130
1130
bystandingImport.module .importedModule ->getName (),
1131
1131
name);
1132
1132
1133
1133
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,
1135
1135
declaringImport.module .importedModule ->getName (),
1136
1136
bystandingImport.module .importedModule ->getName (),
1137
1137
name);
0 commit comments