Swift 1.2: A base-class method is called instead of subclass in release build with whole-module-optimization

Originator:jacob
Number:rdar://20646553 Date Originated:21-Apr-2015 11:44 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3.1 (6D1002)
Classification:Serious Bug Reproducible:Always
 
Summary:
A whole-module-optimization enabled build calls a base-class var instead of the subclassed one

Steps to Reproduce:
In happens in a specific large project and I wasn’t able to reproduce it in a test project, unfortunately.
I’ll give some code sample to explain the set up.

I have a class which includes the following code:
class BaseTransactionEditor: NSViewController, NSTextFieldDelegate {
    var commonViewModel: BaseTransactionEditorViewModel { fatalError("override!") }

override func viewDidAppear() {
// other code
        commonViewModel.newTransaction()
// other code
}

and a subclass like this:
final class PlanTransactionEditor: BaseTransactionEditor, PopoverViewController {
    let viewModel: PlanTransactionViewModel
    override var commonViewModel: BaseTransactionEditorViewModel { return viewModel }

override func viewDidLoad() {
        super.viewDidLoad()
// more code
}

When I launch a build with WMO enabled, Release configuration, upon calling viewDidLoad on the subclass, the application crashes because “fatalError("override!”) executed. I’m attaching the crash log.

Debug build or Release without WMO do not crash.

Expected Results:
Base class should access the subclassed “commonViewModel”

Actual Results:
Base class accesses its own “commonViewModel”

Regression:
Haven’t checked

Comments

Solved

I've run into this issue as well and found that making the base class and var public will get the compiler to handle it as expected.

By Jonathan.Grana at Jan. 18, 2016, 6:40 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!