@@ -94,25 +94,30 @@ struct CodableMacro: ConformanceMacro, MemberMacro {
94
94
else { return }
95
95
96
96
// is a grouped property declaration
97
- if decl. bindings. count > 1 {
98
- var fields : [ TokenSyntax ] = [ ]
99
- var type : TypeSyntax !
97
+ if decl. initializableBindings. count > 1 {
98
+ var variables : [ ( TokenSyntax , TypeSyntax ? ) ] = [ ]
100
99
for binding in decl. initializableBindings
101
100
where binding. pattern. is ( IdentifierPatternSyntax . self) {
102
- fields. append (
103
- binding. pattern
104
- . as ( IdentifierPatternSyntax . self) !. identifier
105
- )
101
+ variables. append ( (
102
+ binding. pattern. as ( IdentifierPatternSyntax . self) !
103
+ . identifier,
104
+ binding. typeAnnotation? . type
105
+ ) )
106
+ }
107
+
108
+ var datas : [ Registrar . Node . Data ] = [ ]
109
+ datas. reserveCapacity ( variables. count)
106
110
107
- guard let fType = binding. typeAnnotation? . type
108
- else { continue }
109
- type = fType
111
+ var latestType : TypeSyntax !
112
+ for (field, type) in variables. reversed ( ) {
113
+ if let type { latestType = type }
114
+ datas. append ( . init( field: field, type: latestType) )
110
115
}
111
116
112
- for field in fields where type != nil {
117
+ for data in datas . reversed ( ) {
113
118
registrar. add (
114
- data: . init ( field : field , type : type ) ,
115
- keyPath: [ field. asKey] ,
119
+ data: data ,
120
+ keyPath: [ data . field. asKey] ,
116
121
context: context
117
122
)
118
123
}
0 commit comments