Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15807] Associated Type Inference fails across module boundaries (Xcode 13.3 RC) #58084

Open
robinkunde opened this issue Feb 1, 2022 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself

Comments

@robinkunde
Copy link
Contributor

Previous ID SR-15807
Radar None
Original Reporter @robinkunde
Type Bug
Environment

Xcode 13.3 b1 (13E5086k)
Apple Swift version 5.6 (swiftlang-5.6.0.320.8 clang-1316.0.18.8)
Xcode 13.3 b2 (13E5095k)
Xcode 13.3 b3 (13E5104i)
Xcode 13.3 RC (13E113)

Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6d760c772c45a460ba5f2eba3f9ee36b

Issue Description:

The following code compiles in Xcode 13.2 but not 13.3b1, 13.3b2, 13.3b3 nor 13.3 RC.

Module A will compile, but Module B will not and fail with the following error:

ModuleB.swift:11:8: type 'ModuleBFoo' does not conform to protocol 'DefaultsSerializable'

ModuleA.swift:12:20: ambiguous inference of associated type 'Bridge': 'BridgeStructSerializable<ModuleBFoo>' vs. 'BridgeStructRawRepresentable<ModuleBFoo>'

ModuleA.swift:18:16: matching requirement '_defaults' to this declaration inferred associated type to 'BridgeStructSerializable<ModuleBFoo>'

ModuleA.swift:22:16: matching requirement '_defaults' to this declaration inferred associated type to 'BridgeStructRawRepresentable<ModuleBFoo>'

Note that `ModuleAFoo` does not run into the same issue.

(Also, Xcode will fail to surface the underlying issue in the Issue Navigator most of the time and just show "type 'ModuleBFoo' does not conform to protocol 'DefaultsSerializable'")

Module A

public protocol DefaultsBridge {
    associatedtype T
}


public struct BridgeStructSerializable<T: Codable>: DefaultsBridge {
}


public struct BridgeStructRawRepresentable<T: RawRepresentable>: DefaultsBridge {
}


public protocol DefaultsSerializable {
    associatedtype Bridge: DefaultsBridge


    static var _defaults: Bridge { get }
}


public extension DefaultsSerializable where Self: Codable {
    static var _defaults: BridgeStructSerializable<Self> { return BridgeStructSerializable() }
}


public extension DefaultsSerializable where Self: RawRepresentable {
    static var _defaults: BridgeStructRawRepresentable<Self> { return BridgeStructRawRepresentable() }
}


public struct ModuleAFoo: Codable, DefaultsSerializable {
}

Module B

import Foundation
import MyLibrary


struct ModuleBFoo: Codable, DefaultsSerializable {
}
@swift-ci
Copy link
Contributor

swift-ci commented Feb 2, 2022

Comment by Alfons (JIRA)

I also see this error appear in Xcode 13.2.1 (type Xyz does not conform to protocol Zyx), but only for "release" builds, i.e. suggestive of compiler settings; hard to reproduce right now.
(And only for protocols that define `static` property requirements).

@sindresorhus
Copy link

We're also seeing this issue: sindresorhus/Defaults#93

@sindresorhus
Copy link

Still reproducible in Xcode 13.3 final...

@swift-ci
Copy link
Contributor

Comment by Weston Mitchell (JIRA)

I am also seeing this error in Xcode 13.3 final

@swift-ci
Copy link
Contributor

Comment by JB Parrett (JIRA)

Ditto above comments - seeing the error on Xcode 13.3. Have reverted back to 13.2.1 in order to continue development.

@swift-ci
Copy link
Contributor

Comment by Ky (JIRA)

I'm still having this issue in Xcode Version 13.3.1 (13E500a)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@Mordil
Copy link

Mordil commented Oct 31, 2022

This still reproduces w/ Swift 5.7 and Xcode 14.0.1 (14A400)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself
Projects
None yet
Development

No branches or pull requests

4 participants