mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Currently it errors when loading a module built from interface if it has package-name.
This disallows building an interface file that imports such module which should be allowed since interface does not contain package symbols unless usableFromInline or inlinable. This change limits erroring only when building a .swift file. Resolves rdar://108633068
This commit is contained in:
@@ -138,6 +138,7 @@ private:
|
||||
void validateResilience(NullablePtr<ModuleDecl> topLevelModule,
|
||||
SourceFile &SF);
|
||||
void validateAllowableClient(ModuleDecl *topLevelModule, SourceFile &SF);
|
||||
void validateInterfaceWithPackageName(ModuleDecl *topLevelModule, SourceFile &SF);
|
||||
|
||||
/// Diagnoses an inability to import \p modulePath in this situation and, if
|
||||
/// \p attrs is provided and has an \p attrKind, invalidates the attribute and
|
||||
@@ -652,8 +653,8 @@ void UnboundImport::validateOptions(NullablePtr<ModuleDecl> topLevelModule,
|
||||
validateTestable(top);
|
||||
validatePrivate(top);
|
||||
validateAllowableClient(top, SF);
|
||||
validateInterfaceWithPackageName(top, SF);
|
||||
}
|
||||
|
||||
validateResilience(topLevelModule, SF);
|
||||
}
|
||||
|
||||
@@ -756,6 +757,28 @@ void UnboundImport::validateAllowableClient(ModuleDecl *importee,
|
||||
}
|
||||
}
|
||||
|
||||
void UnboundImport::validateInterfaceWithPackageName(ModuleDecl *topLevelModule,
|
||||
SourceFile &SF) {
|
||||
assert(topLevelModule);
|
||||
|
||||
// If current source file is interface, don't throw an error
|
||||
if (SF.Kind == SourceFileKind::Interface)
|
||||
return;
|
||||
|
||||
// If source file is .swift or non-interface, show diags when importing an interface file
|
||||
ASTContext &ctx = topLevelModule->getASTContext();
|
||||
if (!topLevelModule->getPackageName().empty() &&
|
||||
topLevelModule->getPackageName().str() == ctx.LangOpts.PackageName &&
|
||||
topLevelModule->isBuiltFromInterface()) {
|
||||
ctx.Diags.diagnose(SourceLoc(),
|
||||
diag::in_package_module_not_compiled_from_source,
|
||||
topLevelModule->getBaseIdentifier(),
|
||||
ctx.LangOpts.PackageName,
|
||||
topLevelModule->getModuleSourceFilename()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
|
||||
SourceFile &SF) {
|
||||
if (import.options.contains(ImportFlags::ImplementationOnly) ||
|
||||
|
||||
Reference in New Issue
Block a user