Skip to content

Avoid an infinite recursion in modules which import themselves #3802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,13 @@ lookupOperatorDeclForName(const FileUnit &File, SourceLoc Loc, Identifier Name,
// Record whether they come from re-exported modules.
// FIXME: We ought to prefer operators elsewhere in this module before we
// check imports.
auto ownModule = SF.getParentModule();
ImportedOperatorsMap<OP_DECL> importedOperators;
for (auto &imported : SourceFile::Impl::getImportsForSourceFile(SF)) {
// Protect against source files that contrive to import their own modules.
if (imported.first.second == ownModule)
continue;

bool isExported =
imported.second.contains(SourceFile::ImportFlags::Exported);
if (!includePrivate && !isExported)
Expand Down
12 changes: 12 additions & 0 deletions test/ClangModules/overlay_with_submodule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend -emit-module %s -sdk %S/Inputs -module-name HasSubmodule -I %S/Inputs/custom-modules -o %t

// REQUIRES: objc_interop

@_exported import HasSubmodule
@_exported import HasSubmodule.Submodule

func useAnOperator() -> Int {
var x : Int
x = 1 + 2 // Forces a lookup of precedence groups
return x
}