Open
Description
Description
Given the definitions
protocol P {}
func g(_: some P) {}
let list = [any P]()
the compiler reports the error type 'any P' cannot conform to 'P'
on $0
passed to g
in the code
list
.map { $0 }
.forEach { g($0) } // error
When I remove the .map
line, everything is fine.
Reproduction
Now, to my surprise, it also compiles without an error if a totally unrelated statement is added to the .forEach
block like in
list
.map { $0 }
.forEach { print(1); g($0) }
Expected behavior
I consider this a bug and expect the very first snippet to compile successfully as well.
Environment
This happens with a recent Swift 6.0.3 compiler on macOS and Linux.
Additional information
Playground: https://swiftfiddle.com/e3xsjlhqsbep3fnbctktirvqza
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.Feature: closuresThe Swift compiler itselfFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: expressionsFeature: generic declarations and typesFeature → existentials: implicit opening of existentials when passed to parameters of generic typeArea → compiler: Semantic analysis