mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Macros] Ignore the @TaskLocal macro attached to vars with projected values.
VarDecls with `@_projectedValueProperty` have already had the property wrapper transform applied. This only impacts swiftinterfaces, and if a swiftinterface was produced against a Concurrency library that does not declare `TaskLocal` as a macro, we need to ignore the macro to avoid producing duplicate declarations. This is only needed temporarily until all swiftinterfaces have been built against the Concurrency library containing the new macro declaration.
This commit is contained in:
@@ -1369,6 +1369,22 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
|
||||
dc = attachedTo->getInnermostDeclContext();
|
||||
}
|
||||
|
||||
// FIXME: compatibility hack for the transition from property wrapper
|
||||
// to macro for TaskLocal.
|
||||
//
|
||||
// VarDecls with `@_projectedValueProperty` have already had the property
|
||||
// wrapper transform applied. This only impacts swiftinterfaces, and if
|
||||
// a swiftinterface was produced against a Concurrency library that does
|
||||
// not declare TaskLocal as a macro, we need to ignore the macro to avoid
|
||||
// producing duplicate declarations. This is only needed temporarily until
|
||||
// all swiftinterfaces have been built against the Concurrency library
|
||||
// containing the new macro declaration.
|
||||
if (auto *var = dyn_cast<VarDecl>(attachedTo)) {
|
||||
if (var->getAttrs().getAttribute<ProjectedValuePropertyAttr>()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ASTContext &ctx = dc->getASTContext();
|
||||
|
||||
auto moduleDecl = dc->getParentModule();
|
||||
|
||||
20
test/ModuleInterface/task_local_attr.swiftinterface
Normal file
20
test/ModuleInterface/task_local_attr.swiftinterface
Normal file
@@ -0,0 +1,20 @@
|
||||
// swift-interface-format-version: 1.0
|
||||
// swift-compiler-version: Swift version 6.0
|
||||
// swift-module-flags: -swift-version 5 -disable-availability-checking
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%s)
|
||||
|
||||
import Swift
|
||||
import _Concurrency
|
||||
|
||||
@_hasMissingDesignatedInitializers final public class C {
|
||||
@_Concurrency.TaskLocal @_projectedValueProperty($x) public static var x: Swift.Int? {
|
||||
get
|
||||
}
|
||||
public static var $x: _Concurrency.TaskLocal<Swift.Int?> {
|
||||
get
|
||||
@available(*, unavailable, message: "use '$myTaskLocal.withValue(_:do:)' instead")
|
||||
set
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user