@@ -94,25 +94,30 @@ struct CodableMacro: ConformanceMacro, MemberMacro {
9494 else { return }
9595
9696 // 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 ? ) ] = [ ]
10099 for binding in decl. initializableBindings
101100 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)
106110
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) )
110115 }
111116
112- for field in fields where type != nil {
117+ for data in datas . reversed ( ) {
113118 registrar. add (
114- data: . init ( field : field , type : type ) ,
115- keyPath: [ field. asKey] ,
119+ data: data ,
120+ keyPath: [ data . field. asKey] ,
116121 context: context
117122 )
118123 }
0 commit comments