@@ -17,6 +17,7 @@ import SwiftSyntax
1717// MARK: - ParamDecl
1818
1919fileprivate protocol ValueParameterSyntax : SyntaxProtocol {
20+ var optionalAttributes : AttributeListSyntax ? { get }
2021 /// The `firstName` with optional type.
2122 ///
2223 /// This is the lowest denominator between `FunctionParameterSyntax` and `EnumCaseParameterSyntax`.
@@ -37,6 +38,9 @@ fileprivate protocol ValueParameterSyntax: SyntaxProtocol {
3738}
3839
3940extension FunctionParameterSyntax : ValueParameterSyntax {
41+ fileprivate var optionalAttributes : AttributeListSyntax ? {
42+ attributes
43+ }
4044 fileprivate var optionalFirstName : TokenSyntax ? {
4145 firstName
4246 }
@@ -47,6 +51,10 @@ extension FunctionParameterSyntax: ValueParameterSyntax {
4751}
4852
4953extension EnumCaseParameterSyntax : ValueParameterSyntax {
54+ fileprivate var optionalAttributes : AttributeListSyntax ? {
55+ nil
56+ }
57+
5058 fileprivate var optionalFirstName : TokenSyntax ? {
5159 firstName
5260 }
@@ -61,6 +69,10 @@ extension EnumCaseParameterSyntax: ValueParameterSyntax {
6169}
6270
6371extension ClosureParameterSyntax : ValueParameterSyntax {
72+ fileprivate var optionalAttributes : AttributeListSyntax ? {
73+ attributes
74+ }
75+
6476 fileprivate var optionalFirstName : TokenSyntax ? {
6577 self . firstName
6678 }
@@ -98,6 +110,15 @@ extension ASTGenVisitor {
98110 /// Generate a ParamDecl. If `argNameByDefault` is true, then the parameter's
99111 /// argument label is inferred from the first name if no second name is present.
100112 private func makeParamDecl( _ node: some ValueParameterSyntax , argNameByDefault: Bool , at index: Int ) -> BridgedParamDecl {
113+ var attrs = BridgedDeclAttributes ( )
114+
115+ // Attributes.
116+ if let attributes = node. optionalAttributes {
117+ self . generateDeclAttributes ( attributeList: attributes) { attr in
118+ attrs. add ( attr)
119+ }
120+ }
121+
101122 // FIXME: This location should be derived from the type repr.
102123 let specifierLoc : BridgedSourceLoc = nil
103124
@@ -147,7 +168,7 @@ extension ASTGenVisitor {
147168 }
148169
149170 // The decl context will be reset to the function later.
150- return . createParsed(
171+ let param = BridgedParamDecl . createParsed (
151172 self . ctx,
152173 declContext: self . declContext,
153174 specifierLoc: specifierLoc,
@@ -159,6 +180,8 @@ extension ASTGenVisitor {
159180 defaultValue: initExpr. asNullable,
160181 defaultValueInitContext: initContext. asNullable
161182 )
183+ param. asDecl. attachParsedAttrs ( attrs)
184+ return param
162185 }
163186
164187 func generate( closureShorthandParameter node : ClosureShorthandParameterSyntax ) -> BridgedParamDecl {
0 commit comments