@@ -50,18 +50,24 @@ extension TaskLocalMacro: PeerMacro {
50
50
message: " '@TaskLocal' property must have name " , id: . incompatibleDecl)
51
51
}
52
52
53
- let type = firstBinding. typeAnnotation? . type
53
+ let originalType = firstBinding. typeAnnotation? . type
54
54
let explicitTypeAnnotation : TypeAnnotationSyntax ?
55
- if let type {
56
- explicitTypeAnnotation = TypeAnnotationSyntax ( type: TypeSyntax ( " TaskLocal< \( type. trimmed) > " ) )
55
+ let taskLocalWrappedType : TypeSyntax ?
56
+ if let forceUnwrappedOptionalType = firstBinding. typeAnnotation? . type. as ( ImplicitlyUnwrappedOptionalTypeSyntax . self) {
57
+ taskLocalWrappedType = TypeSyntax ( " \( forceUnwrappedOptionalType. wrappedType. trimmed) ? " )
58
+ } else {
59
+ taskLocalWrappedType = originalType? . trimmed
60
+ }
61
+ if let taskLocalWrappedType {
62
+ explicitTypeAnnotation = TypeAnnotationSyntax ( type: TypeSyntax ( " TaskLocal< \( taskLocalWrappedType) > " ) )
57
63
} else {
58
64
explicitTypeAnnotation = nil
59
65
}
60
66
61
67
let initialValue : ExprSyntax
62
68
if let initializerValue = firstBinding. initializer? . value {
63
69
initialValue = ExprSyntax ( initializerValue)
64
- } else if let type , type . isOptional {
70
+ } else if let originalType , originalType . isOptional {
65
71
initialValue = ExprSyntax ( NilLiteralExprSyntax ( ) )
66
72
} else {
67
73
throw DiagnosticsError (
@@ -162,7 +168,7 @@ extension TypeSyntax {
162
168
// and T? we can detect the optional.
163
169
fileprivate var isOptional : Bool {
164
170
switch self . as ( TypeSyntaxEnum . self) {
165
- case . optionalType:
171
+ case . optionalType, . implicitlyUnwrappedOptionalType :
166
172
return true
167
173
case . identifierType( let identifierType) :
168
174
return identifierType. name. text == " Optional "
@@ -172,7 +178,8 @@ extension TypeSyntax {
172
178
return false
173
179
}
174
180
return memberType. name. text == " Optional "
175
- default : return false
181
+ default :
182
+ return false
176
183
}
177
184
}
178
185
}
0 commit comments