Skip to content

[SR-10199] Swift 5 Force unwrapped optional is getting warning of casting optional to Any #52599

@swift-ci

Description

@swift-ci
Previous ID SR-10199
Radar None
Original Reporter murthyveda2000 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.0Regression, DiagnosticsQoI, StarterBug, TypeChecker
Assignee @theblixguy
Priority Medium

md5: 4fa37f2df1e096a8d1e88933647f691e

Issue Description:

After upgrading to XCode 10.2 and converting to Swift 5, I am getting a ton of new warnings related to force unwrapped optionals.

Here is a very simple example, but I'm getting the example this error all over the place (especially for the first argument in NSLayoutContraint constructor).

If a property is defined as such:

@IBOutlet weak var shutterButton : UIButton! 

And then later I reference it as an Any:

var views : [Any] = []
views.append(shutterButton) // Expression implicitly coerced from 'UIButton?' to 'Any'

I get the error which I put into the comment there.

Since shutterButter is actually a UIButton and not a UIButton?, I don't think I should be getting this warning and don't get this warning in Swift 4.2.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationgood first issueGood for newcomersregressionswift 5.0type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions