Skip to content

Compiler doesn't indicate missing protocol requirements when method has inverted arguments and protocol is in separate file #85733

@nickasd

Description

@nickasd

Description

The following test case just produces a compiler error Type 'MyA' does not conform to protocol 'A', but does not indicate what is missing nor offers any fix-its. The real issue is that the two arguments of the a method in the first file should be inverted, which would then satisfy the A protocol requirement.

If I move everything into a single file, in Xcode below the compiler error I get two information lines:

  • Unable to infer associated type 'MyB' for protocol 'A'
  • Candidate would match and infer 'MyB' = 'String' if 'String' conformed to 'B'

Commenting out the extension A part shows the information:

  • Protocol requires nested type 'MyB'
  • Add stubs for conformance

If I then click on "Apply" and add the line

typealias CustomB = MyB

to MyA, I finally get a fix-it with the correct method a(b:c:).

All this to realize that my original implementation of the a method had its two arguments inverted.

Reproduction

In the first file:

class MyA: A {
    func a(c: Int, b: MyB) {
    }
}

struct MyB: B {
}

In the second file:

protocol A {
    associatedtype CustomB: B
    
    func a(b: CustomB, c: Int)
}

protocol B {
}

extension A {
    func a(b: String, c: Int) {
        preconditionFailure()
    }
}

Expected behavior

From the beginning I would expect to get a warning that the a(c:b:) method has the arguments in the wrong order, or at least get the Unable to infer associated type 'MyB' for protocol 'A' information that for some reason only appears when everything is in a single file.

Environment

swift-driver version: 1.127.14.1 Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)
Target: arm64-apple-macosx26.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions