Skip to content

[concurrency] allow code to shadow definitions in implicit _Concurrency module #34642

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 2 commits into from
Nov 10, 2020
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
15 changes: 15 additions & 0 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,21 @@ static void recordShadowedDeclsAfterTypeMatch(
}
}

// Next, prefer any other module over the _Concurrency module.
if (auto concurModule = ctx.getLoadedModule(ctx.Id_Concurrency)) {
if ((firstModule == concurModule) != (secondModule == concurModule)) {
// If second module is _Concurrency, then it is shadowed by first.
if (secondModule == concurModule) {
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
5 changes: 5 additions & 0 deletions test/Concurrency/Inputs/ShadowsConcur.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

public struct Task {
public var someProperty : String = "123"
public init() { }
}
13 changes: 13 additions & 0 deletions test/Concurrency/concurrency_module_shadowing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/ShadowsConcur.swiftmodule -module-name ShadowsConcur %S/Inputs/ShadowsConcur.swift
// RUN: %target-typecheck-verify-swift -I %t -enable-experimental-concurrency
// REQUIRES: concurrency


import ShadowsConcur

func f(_ t : Task) -> Bool {
return t.someProperty == "123"
}

func g(_: _Concurrency.Task) {}