Skip to content

Error type 'any P' cannot conform to 'P' fixed by unrelated statement #78436

Open
@SimplyDanny

Description

@SimplyDanny

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.closuresFeature: closurescompilerThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesexpressionsFeature: expressionsgenericsFeature: generic declarations and typesimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeswift 6.1type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions