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-7062] Type inference with AnyObject dispatch & Optional differs in Release+WMO builds #49610
Comments
Does anything else in your project declare a property named |
Note that AnyObject dispatch for properties wraps the result in an ImplicitlyUnwrappedOptional, and |
Here's the only declaration of this property in project so far: @IBOutlet private(set) var contentView: UIView! |
Hm, that could definitely be relevant. It might be assuming you meant that |
@swift-ci create |
What is the type of Have you tried building your project with the Xcode 9.3 betas or a Swift nightly build? I am wondering if you will see the same behavior with those. |
@rudkx The |
@rudkx I hadn't been able to test in the beta yet because one of my dependencies was broken. I worked around that to test this, and I haven't reproduced the error in Xcode 9.3 beta 3 (9Q117m). |
I suspect what was happening here is that we were for some reason selecting the overload of `??` that returns a `T?` rather than `T`. It could be related to the other property called contentView. Are you able to work-around this by using an `if let`? |
The workaround I used in practice was to explicitly annotate the result as ` let contentView: UIView = (source as AnyObject).contentView ?? source.view |
Um. If you're going to work around this at all, why not not use AnyObject dispatch? |
Which workaround I choose to implement is beside the point — this is a valid use of AnyObject dispatch. |
Oh, sure, that's true. AnyObject dispatch itself is just…not great to begin with. |
It can cause your project to rebuild the file more often than it otherwise would during an incremental build, for example. |
Since this appears to be fixed on |
@sharplet, Could you verify if the problem is fixed and if so move the JIRA to "Closed"? |
Happy to close this! |
Attachment: Download
Environment
Xcode Version 9.2 (9C40b)
macOS High Sierra Version 10.13.3
Additional Detail from JIRA
md5: 51d8f3ea57f32c1b31b8730930e2b9db
Issue Description:
This compiler error only occurs when I build in Release configuration or Archive. It doesn't occur if I switch to single-file optimisation (-O). Unfortunately I haven't been able to reproduce it in a smaller project, but I'll attach what I can about the failure.
The code:
The error:
In Debug builds, the type of
contentView
is inferred asUIView
. In Release builds, it is apparently being inferred asUIView?
, causing a compiler error.I've attached a file that includes the invocation of the "Compile Swift source files" step in Xcode.
The text was updated successfully, but these errors were encountered: