@@ -168,6 +168,13 @@ enum Mutability {
168168 case Mutable
169169}
170170
171+ func getUnattributedType( _ type: TypeSyntax ) -> TypeSyntax {
172+ if let attributedType = type. as ( AttributedTypeSyntax . self) {
173+ return attributedType. baseType. trimmed
174+ }
175+ return type. trimmed
176+ }
177+
171178func getTypeName( _ type: TypeSyntax ) throws -> TokenSyntax {
172179 switch type. kind {
173180 case . memberType:
@@ -410,7 +417,7 @@ struct CxxSpanThunkBuilder: ParamPointerBoundsThunkBuilder {
410417 func buildFunctionSignature( _ argTypes: [ Int : TypeSyntax ? ] , _ returnType: TypeSyntax ? ) throws
411418 -> ( FunctionSignatureSyntax , Bool ) {
412419 var types = argTypes
413- let typeName = try getTypeName ( oldType) . text
420+ let typeName = getUnattributedType ( oldType) . description
414421 guard let desugaredType = typeMappings [ typeName] else {
415422 throw DiagnosticError (
416423 " unable to desugar type with name ' \( typeName) ' " , node: node)
@@ -426,7 +433,7 @@ struct CxxSpanThunkBuilder: ParamPointerBoundsThunkBuilder {
426433
427434 func buildFunctionCall( _ pointerArgs: [ Int : ExprSyntax ] ) throws -> ExprSyntax {
428435 var args = pointerArgs
429- let typeName = try getTypeName ( oldType) . text
436+ let typeName = getUnattributedType ( oldType) . description
430437 assert ( args [ index] == nil )
431438 args [ index] = ExprSyntax ( " \( raw: typeName) ( \( raw: name) ) " )
432439 return try base. buildFunctionCall ( args)
@@ -446,7 +453,7 @@ struct CxxSpanReturnThunkBuilder: BoundsCheckedThunkBuilder {
446453 func buildFunctionSignature( _ argTypes: [ Int : TypeSyntax ? ] , _ returnType: TypeSyntax ? ) throws
447454 -> ( FunctionSignatureSyntax , Bool ) {
448455 assert ( returnType == nil )
449- let typeName = try getTypeName ( signature. returnClause!. type) . text
456+ let typeName = getUnattributedType ( signature. returnClause!. type) . description
450457 guard let desugaredType = typeMappings [ typeName] else {
451458 throw DiagnosticError (
452459 " unable to desugar type with name ' \( typeName) ' " , node: node)
@@ -923,19 +930,15 @@ public struct SwiftifyImportMacro: PeerMacro {
923930 return [ ]
924931 }
925932 var result : [ ParamInfo ] = [ ]
926- let process = { type, expr, orig in
927- do {
928- let typeName = try getTypeName ( type) . text
929- if let desugaredType = typeMappings [ typeName] {
930- if let unqualifiedDesugaredType = getUnqualifiedStdName ( desugaredType) {
931- if unqualifiedDesugaredType. starts ( with: " span< " ) {
932- result. append ( CxxSpan ( pointerIndex: expr, nonescaping: false ,
933- dependencies: [ ] , typeMappings: typeMappings, original: orig) )
934- }
933+ let process : ( TypeSyntax , SwiftifyExpr , SyntaxProtocol ) throws -> ( ) = { type, expr, orig in
934+ let typeName = getUnattributedType ( type) . description
935+ if let desugaredType = typeMappings [ typeName] {
936+ if let unqualifiedDesugaredType = getUnqualifiedStdName ( desugaredType) {
937+ if unqualifiedDesugaredType. starts ( with: " span< " ) {
938+ result. append ( CxxSpan ( pointerIndex: expr, nonescaping: false ,
939+ dependencies: [ ] , typeMappings: typeMappings, original: orig) )
935940 }
936941 }
937- } catch is DiagnosticError {
938- // type doesn't match expected pattern
939942 }
940943 }
941944 for (idx, param) in signature. parameterClause. parameters. enumerated ( ) {
0 commit comments