Skip to content

Commit 2c85b5d

Browse files
authored
Merge pull request #3802 from rjmccall/recursive-source-file-import-protection
Avoid an infinite recursion in modules which import themselves
2 parents a99221b + cfd9b83 commit 2c85b5d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/AST/Module.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,13 @@ lookupOperatorDeclForName(const FileUnit &File, SourceLoc Loc, Identifier Name,
10081008
// Record whether they come from re-exported modules.
10091009
// FIXME: We ought to prefer operators elsewhere in this module before we
10101010
// check imports.
1011+
auto ownModule = SF.getParentModule();
10111012
ImportedOperatorsMap<OP_DECL> importedOperators;
10121013
for (auto &imported : SourceFile::Impl::getImportsForSourceFile(SF)) {
1014+
// Protect against source files that contrive to import their own modules.
1015+
if (imported.first.second == ownModule)
1016+
continue;
1017+
10131018
bool isExported =
10141019
imported.second.contains(SourceFile::ImportFlags::Exported);
10151020
if (!includePrivate && !isExported)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-module %s -sdk %S/Inputs -module-name HasSubmodule -I %S/Inputs/custom-modules -o %t
2+
3+
// REQUIRES: objc_interop
4+
5+
@_exported import HasSubmodule
6+
@_exported import HasSubmodule.Submodule
7+
8+
func useAnOperator() -> Int {
9+
var x : Int
10+
x = 1 + 2 // Forces a lookup of precedence groups
11+
return x
12+
}

0 commit comments

Comments
 (0)