Skip to content

[5.7][Sema] Allow code to shadow definitions in implicit _StringProcessing module #58670

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 1 commit into from
May 5, 2022
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
16 changes: 16 additions & 0 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public struct Regex<T> {
public var someProperty: T?
public init() { }
}
Original file line number Diff line number Diff line change
@@ -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<Substring>) -> Bool {
return t.someProperty == "123"
}

func g(_: _StringProcessing.Regex<Substring>) {}