Skip to content

Swift fails to select correct overloaded function with Decimal #63428

@jasonbobier

Description

@jasonbobier

The following code produces the error: member 'attributed' in 'Decimal.FormatStyle' produces result of type 'Decimal.FormatStyle.Attributed', but context expects 'Decimal.FormatStyle

public func formatted(_ formatStyle: Decimal.FormatStyle) -> String {
	Decimal(1).formatted(formatStyle)
}

public func formatted(_ formatStyle: Decimal.FormatStyle.Attributed) -> AttributedString {
	Decimal(1).formatted(formatStyle)
}

formatted(.number.attributed)

But this code works fine:

public func formatted(_ formatStyle: IntegerFormatStyle<Int>) -> String {
	1.formatted(formatStyle)
}

public func formatted(_ formatStyle: IntegerFormatStyle<Int>.Attributed) -> AttributedString {
	1.formatted(formatStyle)
}

formatted(IntegerFormatStyle<Int>.number.attributed)

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0

  • Xcode version info: Version 14.2 (14C18)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfoverloadingFeature: Overloading symbol namestype checkerArea → compiler: Semantic analysistype inferenceFeature: type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions