- Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesexpressionsFeature: expressionsFeature: expressionsimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeFeature → existentials: implicit opening of existentials when passed to parameters of generic typeswift 6.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypesFeature: typesFeature: typesunexpected errorBug: Unexpected errorBug: Unexpected error
Description
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) // <-- OKworks.
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
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesexpressionsFeature: expressionsFeature: expressionsimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeFeature → existentials: implicit opening of existentials when passed to parameters of generic typeswift 6.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypesFeature: typesFeature: typesunexpected errorBug: Unexpected errorBug: Unexpected error