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

[SR-13303] Erroneous warning shown when casting protocol type to dictionary type #55743

Closed
swift-ci opened this issue Jul 27, 2020 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13303
Radar None
Original Reporter ketzusaka (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS X 10.15.6.

Bug is present in Xcode 11.6, Xcode 12 Beta 2. It is not present in Xcode 11.3.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: e1b5118e1d41c3d0c99d8fe0ff8ba714

Issue Description:

I have a protocol that a dictionary conforms to. Types can be cast from this protocol to the concrete dictionary type. This has worked for us before, but is now showing a warning. It works correctly (not showing the warning) on Xcode 11.3.1. The warning shows on Xcode 11.6; we have not tested the in between Xcodes. This issue is still present in Xcode 12 beta 2.

Sample code to reproduce:

import Foundation


protocol Widget {}
extension String: Widget {}
extension Dictionary: Widget where Key == String, Value == Widget {}


var subject: Widget = ["Foo": "Bar"]


// Shows warning: Cast from 'Widget' to unrelated type '[String : String]' always fails
guard let castedSubject = subject as? [String: String] else { fatalError("Cast failed") }
print(castedSubject) // Prints successfully as ["Foo": "Bar"]
@theblixguy
Copy link
Collaborator

This was fixed by @LucianoPAlmeida in #32592 Could you verify using a trunk development snapshot from swift.org?

@swift-ci
Copy link
Collaborator Author

Comment by James Richard (JIRA)

Sweet![]( Verified its good with Xcode 12 Beta 2 and the July 22, 2020 toolchain. Thanks)

@theblixguy
Copy link
Collaborator

No worries! Good to hear that it's fixed for you.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants