-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselftype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
| 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"]Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselftype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis