Skip to content

propertyTypes with --property-types explicit incorrectly format static factory #2445

@AleMaMi

Description

@AleMaMi

Environment

SwiftFormat version 0.60.1

Precondition

Test file (InferredType.swift):

enum Tools {
    static func makeString() -> String {
        "string"
    }
}

func inferredType() {
    let value = Tools.makeString()
    print("Value: \(value)")
}

inferredType()

This compiles properly.

Reproduction

Runing command

$ swiftformat --rules propertyTypes --property-types explicit <InferredType.swift

produces this output

enum Tools {
    static func makeString() -> String {
        "string"
    }
}

func inferredType() {
    let value: Tools = .makeString()
    print("Value: \(value)")
}

inferredType()

which is incorrect (and cannot compile).

Expected result:

enum Tools {
    static func makeString() -> String {
        "string"
    }
}

func inferredType() {
    let value: String = Tools.makeString()
    print("Value: \(value)")
}

inferredType()

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions