Skip to content

Commit 0650b8b

Browse files
authored
Merge pull request #58625 from rxwei/string-processing-shadow
[Sema] Allow code to shadow definitions in implicit _StringProcessing module
2 parents 6bb7eea + 11154e5 commit 0650b8b

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
@@ -660,6 +660,22 @@ static void recordShadowedDeclsAfterTypeMatch(
660660
}
661661
}
662662

663+
// Next, prefer any other module over the _StringProcessing module.
664+
if (auto spModule = ctx.getLoadedModule(ctx.Id_StringProcessing)) {
665+
if ((firstModule == spModule) != (secondModule == spModule)) {
666+
// If second module is _StringProcessing, then it is shadowed by
667+
// first.
668+
if (secondModule == spModule) {
669+
shadowed.insert(secondDecl);
670+
continue;
671+
}
672+
673+
// Otherwise, the first declaration is shadowed by the second.
674+
shadowed.insert(firstDecl);
675+
break;
676+
}
677+
}
678+
663679
// The Foundation overlay introduced Data.withUnsafeBytes, which is
664680
// treated as being ambiguous with SwiftNIO's Data.withUnsafeBytes
665681
// 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)