mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Ensure that #fileID wraps raw identifier module names in backticks.
`#fileID` never accounted for the possibility that someone one have a module alias _itself_, so it always generated the module's real (physical) name. This _technically_ changes the behavior of `#fileID` for self-aliased modules, but since nobody would have ever had a reason to do that before raw identifiers, it's unlikely that this change would affect anyone in practice.
This commit is contained in:
@@ -3333,7 +3333,19 @@ getInfoForUsedFileNames(const ModuleDecl *module) {
|
||||
|
||||
static void computeFileID(const ModuleDecl *module, StringRef name,
|
||||
SmallVectorImpl<char> &result) {
|
||||
result.assign(module->getNameStr().begin(), module->getNameStr().end());
|
||||
// The module might alias itself (e.g., to use a raw identifier as the name
|
||||
// that it references itself with in its own source code), so we need to look
|
||||
// that up.
|
||||
Identifier moduleName = module->getASTContext().getRealModuleName(
|
||||
module->getName(),
|
||||
ASTContext::ModuleAliasLookupOption::aliasFromRealName);
|
||||
if (moduleName.mustAlwaysBeEscaped()) {
|
||||
result.push_back('`');
|
||||
result.append(moduleName.str().begin(), moduleName.str().end());
|
||||
result.push_back('`');
|
||||
} else {
|
||||
result.assign(moduleName.str().begin(), moduleName.str().end());
|
||||
}
|
||||
result.push_back('/');
|
||||
result.append(name.begin(), name.end());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user