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

Enhancing Diagnostics for Accessing Member Types within Existential Metatypes #73420

Open
chiragramani opened this issue May 3, 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

@chiragramani
Copy link

Description

Context: https://forums.swift.org/t/metatype-casting-and-member-access-type-ambiguity-error/71456

protocol Container {
    
}

protocol SpecialisedContainer: Container {
    associatedtype BaseContainer: Container
}

func repro<Root: Container>(root: Root.Type) {
    if let specialised = root as? any SpecialisedContainer.Type {
        let _ = specialised.BaseContainer.self  # Type of expression is ambiguous without a type annotation
        # let _: any Container.Type = specialised.BaseContainer.self # Type of expression is ambiguous without a type annotation
    }
}

Here, no type annotation would make it work:

Type of expression is ambiguous without a type annotation

Thanks to @slavapestov for sharing a helpful workaround and taking his suggestion, creating this issue to advocate for improved diagnostics for the above case.

Reproduction

Context: https://forums.swift.org/t/metatype-casting-and-member-access-type-ambiguity-error/71456

Expected behavior

Diagnostics talking about using a recommended way to open existentials to avoid the above issue.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)

Additional information

No response

@chiragramani chiragramani added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 3, 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