Given the following data structure:
public struct Test {
var trueKey: Bool = true
var falseKey = false
}
if we go through the abstract syntax tree var trueKey: Bool = true
returns, among other things the TypeAnnotationSyntax
as follow:
├─bindingSpecifier: keyword(SwiftSyntax.Keyword.var)
╰─bindings: PatternBindingListSyntax
╰─[0]: PatternBindingSyntax
├─pattern: IdentifierPatternSyntax
│ ╰─identifier: identifier("trueKey")
├─typeAnnotation: TypeAnnotationSyntax
│ ├─colon: colon
│ ╰─type: IdentifierTypeSyntax
│ ╰─name: identifier("Bool")
╰─initializer: InitializerClauseSyntax
├─equal: equal
╰─value: BooleanLiteralExprSyntax
╰─literal: keyword(SwiftSyntax.Keyword.true)
whereas var falseKey = false
does not include the TypeAnnotationSyntax
type as it's inferred and returns:
VariableDeclSyntax
├─bindingSpecifier: keyword(SwiftSyntax.Keyword.var)
╰─bindings: PatternBindingListSyntax
╰─[0]: PatternBindingSyntax
├─pattern: IdentifierPatternSyntax
│ ╰─identifier: identifier("falseKey")
╰─initializer: InitializerClauseSyntax
├─equal: equal
╰─value: BooleanLiteralExprSyntax
╰─literal: keyword(SwiftSyntax.Keyword.false)
Is there a reason for that? Moreover is there a way to extract the type in a generic way?