Skip to content

swift-syntax extension to infer types from expressions based on literal information

License

Notifications You must be signed in to change notification settings

p-x9/swift-literal-type-inference

Repository files navigation

LiteralTypeInference

swift-syntax extension to infer types from expressions based on literal information.

Github issues Github forks Github stars Github top language

Usage

Implemented as an extension of the ExprSyntaxProtocol.

The type inferred from literal information can be obtained from the inferredType property.

import SwiftSyntax
import SwiftSyntaxBuilder
import LiteralTypeInference


let expr: ExprSyntax = """
[
    "item1": [
        (1, 2.0, "3", true),
        (1.0, 2, "7", false),
        (nil, nil, nil, false)
    ],
    "item2": [],
    "item3": [
        (1, 2, "3", true)
    ]
]
"""

// Get the type of expr from the `inferredType` property
let type = expr.inferredType

print(type?.formatted().description)
// => [String: [(Double?, Double?, String?, Bool)]]

License

LiteralTypeInference is released under the MIT License. See LICENSE

About

swift-syntax extension to infer types from expressions based on literal information

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages