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

Enabling upcoming feature ExistentialAny does not work for standard library protocols. #65034

Closed
ensan-hcl opened this issue Apr 9, 2023 · 1 comment · Fixed by #65112 or #65146
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values swift 5.9 type checker Area → compiler: Semantic analysis

Comments

@ensan-hcl
Copy link
Contributor

Description

Enabling upcoming feature ExistentialAny does not work for standard library protocols.

For example, it should produce a compile error, considering Decoder is a bare protocol. However, the compiler does not produce any error or warning, even though for other non-standard library protocols it produces errors and warnings correctly.

init(from decoder: Decoder) throws { /* ... */ }

Steps to reproduce

  1. swift repl -enable-upcoming-feature ExistentialAny
  2. put following;
protocol P {}
extension Int: P {}
  1. put following:
let value: P = 42

It produces an error

expression failed to parse:
error: repl.swift:5:12: error: use of protocol 'P' as a type must be written 'any P'
let value: P = 42
           ^
           any P
  1. put following;
let value: Codable = 42

It works!

Expected behavior
Codable should also produce a compile error, but it doesn't.

Environment

  • Swift compiler version info
    swiftc -version
    swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
    Target: x86_64-apple-macosx13.0
    
  • Xcode version info
    Xcode 14.3
    Build version 14E222b
    
  • Deployment target: N/A

As I checked, it seems any P check is not working for standard library protocols without associated types including Codable, Decoder, Encoder, CustomStringConvertible, CustomDebugStringConvertible, ExpressibleBy*Literal, and so on.

Forum thread: https://forums.swift.org/t/any-p-check-doesnt-work-for-standard-library-protocols/64276

@ensan-hcl ensan-hcl added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 9, 2023
@AnthonyLatsis AnthonyLatsis added diagnostics QoI Bug: Diagnostics Quality of Implementation existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values compiler The Swift compiler in itself swift 5.9 type checker Area → compiler: Semantic analysis TypeResolver and removed triage needed This issue needs more specific labels labels Apr 12, 2023
@AnthonyLatsis AnthonyLatsis self-assigned this Apr 12, 2023
@ensan-hcl
Copy link
Contributor Author

Thanks!

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. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values swift 5.9 type checker Area → compiler: Semantic analysis
Projects
None yet
2 participants