Skip to content

[SR-13415] Xcode 12b5: source incompatibility w/ generic overloads & trailing closures #55856

Open
@swift-ci

Description

@swift-ci
Previous ID SR-13415
Radar rdar://problem/67451813
Original Reporter rydermackay (JIRA User)
Type Bug
Environment

Xcode 12b5 (12A8189h)

macOS 11.0b4 (20A5343i)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: be271db21582958117b1f424ae61ac39

Issue Description:

I'm not sure if this a regression or a case of ill-formed code no longer being accepted.

Part of our codebase uses ReactiveSwift which defines types similar to the following:

struct Box<Value> {
    let value: Value
}

extension Box {
    // 1.
    func map<T>(_ f: @escaping (Value) -> T) -> Box<T> {
        return Box<T>(value: f(value))
    }
    
    // 2.
    func map<T>(_ value: T) -> Box<T> {
        return map { _ in value }
    }
    
    // 3.
    func map<T>(_ keyPath: KeyPath<Value, T>) -> Box<T> {
        return map { $0[keyPath: keyPath] }
    }
}

I just noticed that our own client code, which has "worked" for several releases, no longer compiles in Xcode 12b5. It looks more or less like this:

func test(input: Box<Void>) -> Box<String> {
    // Xcode 12b4: output is Box<String> (overload 1)
    // Xcode 12b5: output is Box<() -> String> (overload 2, but only when 3 exists!!)
    let output = input.map { "foo" }
    return output
}

The really weird thing is it compiles if I remove the seemingly unrelated overload 3 that takes a key path.

I wonder if this might be related to the recent forward scanning trailing closures changes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdeclarationsFeature: declarationsfuncFeature → declarations: Functionsoverload resolutionArea → compiler → type checker: Overload resolution (ranking)regressionswift 5.9type checkerArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions