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

Unexpected ambiguous type error when assigning to conforming primary associated type #72977

Open
hydrixos opened this issue Apr 11, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@hydrixos
Copy link

Description

In the following example I have a protocol type "B" that conforms to a protocol type "A". As soon as I try to assign a function result of type "any B" to a variable of type "any A", the compiler responds with a "Type of expression is ambiguous" error.

Reproduction

protocol A<Arg1> {
	associatedtype Arg1
}

protocol B: A where Arg1 == Int {
}

func makeB() -> any B {
	// ...
}

// Results in "Type of expression is ambiguous without type annotation"
let x: (any A<Int>) = makeB()

Expected behavior

  • I would expect that such an assignment just works.
  • If this is not possible due to limitations of primary associated types: I think the error message could be a bit more specific to explain the limitation.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@hydrixos hydrixos added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 11, 2024
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant