-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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.closuresFeature: closuresFeature: closurescompilerThe 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: expressionsgenericsFeature: generic declarations and typesFeature: generic declarations and typesimplicit 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.1type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
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
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closuresFeature: closurescompilerThe 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: expressionsgenericsFeature: generic declarations and typesFeature: generic declarations and typesimplicit 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.1type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis