LiteralTypeInference

0.1.0

swift-syntax extension to infer types from expressions based on literal information
p-x9/swift-literal-type-inference

What's New

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?.expected?.formatted().description)
// => [String: [(Double?, Double?, String?, Bool)]]

License

LiteralTypeInference is released under the MIT License. See LICENSE

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun May 05 2024 13:27:51 GMT-0900 (Hawaii-Aleutian Daylight Time)