Skip to content

Implicit opened existentials do not work sometimes #74937

@shivatinker

Description

@shivatinker

Description

I have found a case, where existential type is not implicitly opened upon passing in a generic function. Strangely enough, passing it through an intermediate variable fixes the issue.

Reproduction

protocol Base {} struct A: Base {} struct B: Base {} func foo(_ value: some Base) { } let things: [any Base] = [A(), B()] foo(things.first!) // <-- Type 'any Base' cannot conform to 'Base'

However,

let things: [any Base] = [A(), B()] let thing = things.first! foo(thing) // <-- OK

works.

Expected behavior

Existential should be opened in foo(things.first!) implicitly.

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Target: arm64-apple-macosx15.0 

Additional information

https://forums.swift.org/t/strange-compiler-behaviour-in-implicitly-opened-existentials/72916

P.S. If you will find this issue easy-looking, I may attempt to try to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesexpressionsFeature: expressionsimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeswift 6.0type checkerArea → compiler: Semantic analysistypesFeature: typesunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions