swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.6k stars 10.37k forks source link

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

Open soumyamahunt opened 1 month ago

soumyamahunt commented 1 month ago

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/@__swiftmacro16MetaCodableTests09SomeActorB00B0fMe.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