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
SR-10589 Compiler warning about "cast always fails" but it doesn't
Issue Description:
The following code generates warnings that the casts will always fail, despite them succeeding at runtime:
leta: [Any] = [String?.some("hello") as Any, String?.none as Any]// warning: Cast from '[Any]' to unrelated type '[String?]' always failsprint(a is [String?]) // true// warning: Cast from '[Any]' to unrelated type '[String?]' always failsprint(a as? [String?] as Any) // Optional([Optional("hello"), nil])
Though if we are to make this consistent, we should reject the above code, as we currently reject type to more optional type casts:
leta: Any = String?.some("") asAnyprint(aisString?) // error: Cannot downcast from 'Any' to a more optional type 'String?'
Either that or we should accept both cases without warnings (I'm not sure whether the downcast to more optional type error is intended in the case of existential and archetype operands).
The text was updated successfully, but these errors were encountered:
Environment
Apple Swift version 4.2-dev (LLVM c4ec2ab808, Clang af436f313e, Swift 347ff6a)
Target: x86_64-apple-darwin17.4.0
Additional Detail from JIRA
md5: 4ff77d5d9933586592b4e6c987ebccde
Parent-Task:
is duplicated by:
Issue Description:
The following code generates warnings that the casts will always fail, despite them succeeding at runtime:
Though if we are to make this consistent, we should reject the above code, as we currently reject type to more optional type casts:
Either that or we should accept both cases without warnings (I'm not sure whether the downcast to more optional type error is intended in the case of existential and archetype operands).
The text was updated successfully, but these errors were encountered: