Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SimplyDanny opened this issue Jan 4, 2025 · 0 comments
Open
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

Comments

@SimplyDanny
Copy link

SimplyDanny commented Jan 4, 2025

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

@SimplyDanny SimplyDanny added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 4, 2025
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself type checker Area → compiler: Semantic analysis generics Feature: generic declarations and types closures Feature: closures existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values expressions Feature: expressions implicit existential opening Feature → existentials: implicit opening of existentials when passed to parameters of generic type swift 6.1 and removed triage needed This issue needs more specific labels labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants