diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 1453b00e2f351..21813c89178ab 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -528,6 +528,22 @@ static void recordShadowedDeclsAfterTypeMatch( } } + // Next, prefer any other module over the _StringProcessing module. + if (auto spModule = ctx.getLoadedModule(ctx.Id_StringProcessing)) { + if ((firstModule == spModule) != (secondModule == spModule)) { + // If second module is _StringProcessing, then it is shadowed by + // first. + if (secondModule == spModule) { + shadowed.insert(secondDecl); + continue; + } + + // Otherwise, the first declaration is shadowed by the second. + shadowed.insert(firstDecl); + break; + } + } + // The Foundation overlay introduced Data.withUnsafeBytes, which is // treated as being ambiguous with SwiftNIO's Data.withUnsafeBytes // extension. Apply a special-case name shadowing rule to use the diff --git a/test/StringProcessing/Sema/Inputs/ShadowsStringProcessing.swift b/test/StringProcessing/Sema/Inputs/ShadowsStringProcessing.swift new file mode 100644 index 0000000000000..8993cb10f4318 --- /dev/null +++ b/test/StringProcessing/Sema/Inputs/ShadowsStringProcessing.swift @@ -0,0 +1,4 @@ + public struct Regex { + public var someProperty: T? + public init() { } + } diff --git a/test/StringProcessing/Sema/string_processing_module_shadowing.swift b/test/StringProcessing/Sema/string_processing_module_shadowing.swift new file mode 100644 index 0000000000000..374d8fba32605 --- /dev/null +++ b/test/StringProcessing/Sema/string_processing_module_shadowing.swift @@ -0,0 +1,11 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/ShadowsStringProcessing.swiftmodule -module-name ShadowsStringProcessing %S/Inputs/ShadowsStringProcessing.swift -disable-availability-checking +// RUN: %target-typecheck-verify-swift -I %t -enable-experimental-string-processing -disable-availability-checking + +import ShadowsStringProcessing + +func f(_ t : Regex) -> Bool { + return t.someProperty == "123" +} + +func g(_: _StringProcessing.Regex) {}