8000 [6.0] [Macro] Compiler error when producing extension macro with `@preconcurrency` attribute · Issue #76745 · swiftlang/swift · GitHub
[go: up one dir, main page]

Skip to content

[6.0] [Macro] Compiler error when producing extension macro with @preconcurrency attribute #76745

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

Closed
soumyamahunt opened this issue Sep 27, 2024 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift macro Feature → declarations: Swift `macro` declarations

Comments

@soumyamahunt
Copy link

Description

If an extension macro produces an extension that declares conformance to a protocol with @preconcurrency attribute. The compiler gives error:

'preconcurrency' attribute only applies in inheritance clauses

But inlining the macro expansion, code is compiled without any error.

For example let's suppose @Codable is an extension macro that produces Decodable conformance to actor, i.e.

@Codable
actor SomeActorCodable {
    @CodedIn("deeply", "nested1")
    let value1: String
    @CodedIn("deeply", "nested2")
    var value2: String?
    @CodedIn("deeply", "nested3")
    var value3: String!
}

produces an extension declaration

extension SomeActorCodable: @preconcurrency Decodable {
}

Compiler shows following error for produced expansion:

Showing All Messages
/var/folders/r6/gctp971x7bgg0sgxjqy8z7s00000gq/T/swift-generated-sources/@_swiftmacro_16MetaCodableTests09SomeActorB00B0fMe.swift:1:29: 'preconcurrency' attribute only applies in inheritance clauses

Reproduction

  1. Add MetaCodable swift package: https://github.com/SwiftyLab/MetaCodable targeting branch swift-testing.

  2. Add an actor declaration with @Codable macro attached, i.e.

    @Codable
    actor SomeActorCodable {
        @CodedIn("deeply", "nested1")
        let value1: String
        @CodedIn("deeply", "nested2")
        var value2: String?
        @CodedIn("deeply", "nested3")
        var value3: String!
    }
    
  3. See the error when macro expanded during compile/build.

Expected behavior

Macro expansion should be accepted.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: x86_64-apple-macosx14.0

Additional information

No response

@soumyamahunt soumyamahunt added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 27, 2024
@jacbro2021
Copy link

@soumyamahunt Were you able to find a work around for this issue? I am having the same problem when creating an extension macro that adds @unchecked Sendable.

@ahoppen ahoppen added swift macro Feature → declarations: Swift `macro` declarations and removed triage needed This issue needs more specific labels labels Apr 23, 2025
@ahoppen
Copy link
Member
ahoppen commented Apr 23, 2025

Reduced the issue to the following sample macro.

Test.zip

@DougGregor
Copy link
Member

This is fixed for Swift 6.2, via #81249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift macro Feature → declarations: Swift `macro` declarations
Projects
None yet
Development

No branches or pull requests

4 participants
0