@@ -32,53 +32,23 @@ import Foundation
3232// MARK: - Variable Literal Initializers
3333
3434extension Variable {
35- // swiftlint:disable cyclomatic_complexity
3635 /// Creates a `let` or `var` declaration with a literal value.
3736 /// - Parameters:
3837 /// - kind: The kind of variable, either ``VariableKind/let`` or ``VariableKind/var``.
3938 /// - name: The name of the variable.
4039 /// - equals: A literal value that conforms to ``LiteralValue``.
41- public init < T: LiteralValue > (
40+ public init < T: CodeBlockable & LiteralValue > (
4241 _ kind: VariableKind , name: String , equals value: T
4342 ) {
44- let defaultValue : CodeBlock
45- if let literal = value as? Literal {
46- defaultValue = literal
47- } else if let tuple = value as? TupleLiteral {
48- defaultValue = Literal . tuple ( tuple. elements)
49- } else if let array = value as? ArrayLiteral {
50- defaultValue = Literal . array ( array. elements)
51- } else if let dict = value as? DictionaryLiteral {
52- defaultValue = Literal . dictionary ( dict. elements)
53- } else if let array = value as? [ String ] {
54- defaultValue = Literal . array ( array. map { . string( $0) } )
55- } else if let dict = value as? [ Int : String ] {
56- defaultValue = Literal . dictionary ( dict. map { ( . integer( $0. key) , . string( $0. value) ) } )
57- } else if let dictExpr = value as? DictionaryExpr {
58- defaultValue = dictExpr
59- } else if let initExpr = value as? Init {
60- defaultValue = initExpr
61- } else if let codeBlock = value as? CodeBlock {
62- defaultValue = codeBlock
63- } else {
64- // For any other LiteralValue type that doesn't conform to CodeBlock,
65- // create a fallback or throw an error
66- fatalError (
67- " Variable: Unsupported LiteralValue type that doesn't conform to CodeBlock: \( T . self) "
68- )
69- }
70-
7143 self . init (
7244 kind: kind,
7345 name: name,
7446 type: value. typeName,
75- defaultValue: defaultValue ,
47+ defaultValue: value . codeBlock ,
7648 explicitType: false
7749 )
7850 }
7951
80- // swiftlint:enable cyclomatic_complexity
81-
8252 /// Creates a `let` or `var` declaration with a string literal value.
8353 /// - Parameters:
8454 /// - kind: The kind of variable, either ``VariableKind/let`` or ``VariableKind/var``.
0 commit comments