Skip to content

Commit aeae6c9

Browse files
authored
Merge pull request #58670 from rxwei/cherry-pick-58625
[5.7][Sema] Allow code to shadow definitions in implicit _StringProcessing module
2 parents 0a0972d + 533c7b7 commit aeae6c9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/AST/NameLookup.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,22 @@ static void recordShadowedDeclsAfterTypeMatch(
528528
}
529529
}
530530

531+
// Next, prefer any other module over the _StringProcessing module.
532+
if (auto spModule = ctx.getLoadedModule(ctx.Id_StringProcessing)) {
533+
if ((firstModule == spModule) != (secondModule == spModule)) {
534+
// If second module is _StringProcessing, then it is shadowed by
535+
// first.
536+
if (secondModule == spModule) {
537+
shadowed.insert(secondDecl);
538+
continue;
539+
}
540+
541+
// Otherwise, the first declaration is shadowed by the second.
542+
shadowed.insert(firstDecl);
543+
break;
544+
}
545+
}
546+
531547
// The Foundation overlay introduced Data.withUnsafeBytes, which is
532548
// treated as being ambiguous with SwiftNIO's Data.withUnsafeBytes
533549
// extension. Apply a special-case name shadowing rule to use the
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public struct Regex<T> {
2+
public var someProperty: T?
3+
public init() { }
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/ShadowsStringProcessing.swiftmodule -module-name ShadowsStringProcessing %S/Inputs/ShadowsStringProcessing.swift -disable-availability-checking
3+
// RUN: %target-typecheck-verify-swift -I %t -enable-experimental-string-processing -disable-availability-checking
4+
5+
import ShadowsStringProcessing
6+
7+
func f(_ t : Regex<Substring>) -> Bool {
8+
return t.someProperty == "123"
9+
}
10+
11+
func g(_: _StringProcessing.Regex<Substring>) {}

0 commit comments

Comments
 (0)