Error type 'any P' cannot conform to 'P'
fixed by unrelated statement
#78436
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
closures
Feature: closures
compiler
The Swift compiler itself
existentials
Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values
expressions
Feature: expressions
generics
Feature: generic declarations and types
implicit existential opening
Feature → existentials: implicit opening of existentials when passed to parameters of generic type
swift 6.1
type checker
Area → compiler: Semantic analysis
Description
Given the definitions
the compiler reports the error
type 'any P' cannot conform to 'P'
on$0
passed tog
in the codeWhen 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 inExpected 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
The text was updated successfully, but these errors were encountered: