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-9667] Type inference fails even though enough information is specified #52111

Open
swift-ci opened this issue Jan 15, 2019 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9667
Radar None
Original Reporter Anandabits (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: d3f707ecb25568eafaa2c2d3cff5a766

Issue Description:

The following code demonstrates how type inference succeeds when a type parameter is bound in an extension constraint but fails when the same type parameter is bound by the expression context. I believe this is a bug or an undesirable limitation of the current implementation. If it isn't either of those and is just not possible in the latter context I am interested in understanding why that is the case.

protocol P {
    associatedtype A
}
struct G<A>: P {}
protocol I {
    associatedtype A
    associatedtype C: P
    init(_: C)
}
struct F<C: P>: I {
    typealias A = C.A
    init(_: C) {}
}
extension I where C == G<Int> {
    static var int: Self { return .init(.init()) }
}
extension I where C == G<A>, A: Numeric {
    static var numeric: Self { return .init(.init()) }
}
func foo<C: P>(_: F<C>, a: C.A.Type = C.A.self) {}
func test() {
    // works when G.A is specified as a constraint on the extension
    foo(.int)
    // does not work when G.A is specified in the expression context
    foo(.numeric, a: Int.self) // Generic parameter 'C' could not be inferred
}
@belkadan
Copy link
Contributor

cc @xedin

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants