Swift code in class hierarchy works differently split across files than in a single file

Originator:gothick.fysh
Number:rdar://17249478 Date Originated:10 June 2014
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
In the attached code, I have two classes, Base and Derived, and some very simple code to exercise them, printing a result that should eventually be generated by the "Derived" class. In a command-line project, if I have all the code together in a single file, the result is what I expect; both println statements output "Derived contents, dynamically generated".

However, if I take the Base and Derived class definitions, and put them in their own files, making no other changes, then I get "Derived contents, dynamically generated", followed by "Base contents", indicating that the wrong getter is being called.

Steps to Reproduce:
1. Take the code in "single_file", attached, and put it in a new Xcode OS X command-line utility Swift project.
2. Run it.
3. Cut and paste the code for the "Derived" class out into a new file called "derived.swift"
4. Cut and paste the code for the "Base" class out into a new file called "derived.swift"
5. (At this point, you should have code that looks like the "split_across_files" folder, attached)
6. Re-run the project. 
7. Observe difference in output

Expected Results:
I'd expect that in both cases, the Derived class's setter would be used, resulting in "Derived contents, dynamically generated" to appear twice.

Actual Results:
With the code in a single source file, I get the expected results. With the code split across three source files, I get "Derived contents, dynamically generated", followed by "Base contents", which seems to indicate that the wrong getter is being called.

Version:
Xcode Version 6.0 (6A215l)
OS X 10.9.4 Build 13E9

Notes:
First observed while investigating this Stack Overflow question: http://stackoverflow.com/questions/24135741/calling-a-subclasss-getter-in-swift/24136038?noredirect=1#comment37248938_24136038

Configuration:


Attachments:


------
//
//  main.swift
//  derivation
//
//  Created by Matt Gibson on 10/06/2014.
//  Copyright (c) 2014 Matt Gibson Creative. All rights reserved.
//

import Foundation

class Base {
    var contents = "Base contents"
    var description: String {
    get {
        return self.contents
    }
    }
}

class Derived : Base {
    override var contents: String {
    get {
        return "Derived contents, dynamically generated"
    }
    set { }
    }
}

let d = Derived()
println(d.contents) // Prints "Derived contents, dynamically generated"
println(d.description) // Prints "Derived contents, dynamically generated" if single source file, "Base contents" if classes above are split out into their own files.

Comments


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!