You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protocol MyProto {
var title: String? { get }
}
let tuple = (x: 100, y: 100)
// Results in a warning as expected: Cast always fails
let castedTupleToInt = tuple as? Int
// No warning, although cast will always fail
let castedTuple = tuple as? MyProto
The way I see it, it should be pretty easy for the compiler to detect that casting a tuple to a protocol always fails, since there’s currently no way for a tuple to conform to a protocol.
Motivation:
We came across the bug when we refactored a method to return a tuple instead of a protocol type, and thought the compiler would make us aware of all the call sites that need to adopt the the refactored return type. However, wherever we casted the return type, no warning was raised and the code just silently returned early because the cast always fails at runtime (as it should, of course).
Previous Discussion:
There was a brief discussion on the swift-users mailing list: "Casting tuples to protocols always fails (and the compiler should know)"
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: ec7c68ee3a0e3d19091e8a48bb0ee42d
Issue Description:
Reproduce:
This snippet reproduces the issue:
The way I see it, it should be pretty easy for the compiler to detect that casting a tuple to a protocol always fails, since there’s currently no way for a tuple to conform to a protocol.
Motivation:
We came across the bug when we refactored a method to return a tuple instead of a protocol type, and thought the compiler would make us aware of all the call sites that need to adopt the the refactored return type. However, wherever we casted the return type, no warning was raised and the code just silently returned early because the cast always fails at runtime (as it should, of course).
Previous Discussion:
There was a brief discussion on the swift-users mailing list: "Casting tuples to protocols always fails (and the compiler should know)"
The text was updated successfully, but these errors were encountered: