Open
Description
Description
No response
Reproduction
For e.g:
import SwiftSyntax
import SwiftSyntaxMacros
public struct SetterMacro: AccessorMacro, Macro {
public static func expansion(
of node: AttributeSyntax,
providingAccessorsOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [AccessorDeclSyntax] {
return [
"""
set {
_storage = newValue
}
""",
]
}
}
and:
@attached(accessor)
macro setterMacro() =
#externalMacro(module: "MacroDefinition", type: "SetterMacro")
struct S {
var _storage = 0
@setterMacro
var x: Int {
get { _storage }
}
@setterMacro
subscript() -> Int {
get { _storage }
}
}
you get the error for its use with the subscript:
@__swiftmacro_4main1SV9subscript11setterMacrofMa_.swift:2:9: error: instance member '_storage' cannot be used on type 'S'; did you mean to use a value of this type instead? [instance_member_use_on_type]
_storage = newValue
^~~~~~~~
main.swift:145:3: note: in expansion of macro 'setterMacro' on subscript 'subscript()' here [in_macro_expansion]
@setterMacro
^~~~~~~~~~~~
Expected behavior
Given this works for the computed property, it seems like this ought to work for the subscript too.
Environment
Swift version 5.11-dev (LLVM 572a5a4fbafb69e, Swift 484fc77)
Target: arm64-apple-macosx14.0
Additional information
No response