Skip to content

Commit 8dcfadd

Browse files
committed
[Sema] Track the access level modifier on import full range
1 parent 23d9def commit 8dcfadd

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

include/swift/AST/Import.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,19 +591,19 @@ struct AttributedImport {
591591

592592
/// Location of the attribute that defined \c accessLevel. Also indicates
593593
/// if the access level was implicit or explicit.
594-
SourceLoc accessLevelLoc;
594+
SourceRange accessLevelRange;
595595

596596
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
597597
ImportOptions options = ImportOptions(),
598598
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
599599
SourceRange preconcurrencyRange = {},
600600
llvm::Optional<AccessLevel> docVisibility = llvm::None,
601601
AccessLevel accessLevel = AccessLevel::Public,
602-
SourceLoc accessLevelLoc = SourceLoc())
602+
SourceRange accessLevelRange = SourceRange())
603603
: module(module), importLoc(importLoc), options(options),
604604
sourceFileArg(filename), spiGroups(spiGroups),
605605
preconcurrencyRange(preconcurrencyRange), docVisibility(docVisibility),
606-
accessLevel(accessLevel), accessLevelLoc(accessLevelLoc) {
606+
accessLevel(accessLevel), accessLevelRange(accessLevelRange) {
607607
assert(!(options.contains(ImportFlags::Exported) &&
608608
options.contains(ImportFlags::ImplementationOnly)) ||
609609
options.contains(ImportFlags::Reserved));
@@ -614,7 +614,7 @@ struct AttributedImport {
614614
: AttributedImport(module, other.importLoc, other.options,
615615
other.sourceFileArg, other.spiGroups,
616616
other.preconcurrencyRange, other.docVisibility,
617-
other.accessLevel, other.accessLevelLoc) { }
617+
other.accessLevel, other.accessLevelRange) { }
618618

619619
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
620620
const AttributedImport<ModuleInfo> &rhs) {
@@ -624,7 +624,7 @@ struct AttributedImport {
624624
lhs.spiGroups == rhs.spiGroups &&
625625
lhs.docVisibility == rhs.docVisibility &&
626626
lhs.accessLevel == rhs.accessLevel &&
627-
lhs.accessLevelLoc == rhs.accessLevelLoc;
627+
lhs.accessLevelRange == rhs.accessLevelRange;
628628
}
629629

630630
AttributedImport<ImportedModule> getLoaded(ModuleDecl *loadedModule) const {
@@ -802,7 +802,7 @@ struct DenseMapInfo<swift::AttributedImport<ModuleInfo>> {
802802
a.spiGroups == b.spiGroups &&
803803
a.docVisibility == b.docVisibility &&
804804
a.accessLevel == b.accessLevel &&
805-
a.accessLevelLoc == b.accessLevelLoc;
805+
a.accessLevelRange == b.accessLevelRange;
806806
}
807807
};
808808
}

lib/Sema/ImportResolution.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ UnboundImport::UnboundImport(ImportDecl *ID)
570570

571571
import.accessLevel = ID->getAccessLevel();
572572
if (auto attr = ID->getAttrs().getAttribute<AccessControlAttr>()) {
573-
import.accessLevelLoc = attr->getLocation();
573+
import.accessLevelRange = attr->getLocation();
574574
}
575575

576576
if (ID->getAttrs().hasAttribute<SPIOnlyAttr>())
@@ -822,9 +822,9 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
822822
SF.getParentModule()->getName());
823823

824824
if (ctx.LangOpts.hasFeature(Feature::AccessLevelOnImport)) {
825-
SourceLoc attrLoc = import.accessLevelLoc;
826-
if (attrLoc.isValid())
827-
inFlight.fixItReplace(attrLoc, "internal");
825+
SourceRange attrRange = import.accessLevelRange;
826+
if (attrRange.isValid())
827+
inFlight.fixItReplace(attrRange, "internal");
828828
else
829829
inFlight.fixItInsert(import.importLoc, "internal ");
830830
} else {

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
115115
ImportAccessLevel problematicImport = D->getImportAccessFrom(DC);
116116
if (problematicImport.has_value() &&
117117
problematicImport->accessLevel < D->getFormalAccess()) {
118-
Context.Diags.diagnose(problematicImport->accessLevelLoc,
118+
Context.Diags.diagnose(problematicImport->importLoc,
119119
diag::decl_import_via_here, D,
120120
problematicImport->accessLevel,
121121
problematicImport->module.importedModule);

lib/Sema/TypeCheckAccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,13 @@ static void noteLimitingImport(ASTContext &ctx,
339339

340340
if (auto ITR = dyn_cast_or_null<IdentTypeRepr>(complainRepr)) {
341341
ValueDecl *VD = ITR->getBoundDecl();
342-
ctx.Diags.diagnose(limitImport->accessLevelLoc,
342+
ctx.Diags.diagnose(limitImport->importLoc,
343343
diag::decl_import_via_here,
344344
VD,
345345
limitImport->accessLevel,
346346
limitImport->module.importedModule);
347347
} else {
348-
ctx.Diags.diagnose(limitImport->accessLevelLoc, diag::module_imported_here,
348+
ctx.Diags.diagnose(limitImport->importLoc, diag::module_imported_here,
349349
limitImport->module.importedModule,
350350
limitImport->accessLevel);
351351
}

0 commit comments

Comments
 (0)