Xcode 7b3: Swiftc crashes when overriding hashValue in @objc subclass of Swift class

Originator:davidp
Number:rdar://21881476 Date Originated:7/17/15
Status:Open Resolved:
Product:Xcode Product Version:7.0 beta 3
Classification:crash Reproducible:always
 
The following code causes the Swift compiler to crash:

public func == (lhs: AbstractMessage, rhs: AbstractMessage) -> Bool
{
    return lhs.hashValue == rhs.hashValue
}
public class AbstractMessage:Hashable {
    public var hashValue: Int {
        get {
            return 7
        }
    }
}

@objc public class ObjectiveCMessage : AbstractMessage {
    override public var hashValue:Int {
        get {
            return 8
        }
    }
}

Removing the @objc decorator or removing the override of hashValue will avoid the crash.

Steps to Reproduce:
Compile the code above, either in a Playground or in an iOS project.

Expected Results:
Compiler to not crash.

Actual Results:
Compiler crashes with a failed assertion. Will attach the full log, but the assertion line is:

Assertion failed: (SILFn && "no IR function for swift-as-objc thunk"), function findSwiftAsObjCThunk, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.45/src/swift/lib/IRGen/GenObjC.cpp, line 931.

Same code compiles fine in 6.4, making this a regression.

Comments

This is fixed as of Xcode 7 beta 4, in that the compiler no longer crashes. It now reports the following error:

/Users/davidp/dev/SwiftCompilerCrashes/SwiftCompilerCrashes/SwiftObjcThunkAssertionFails.swift:23:14: error: only classes that inherit from NSObject can be declared @objc @objc public class ObjectiveCMessage : AbstractMessage {

I have marked it as Resolved from the reporter side in radar; will hold off on their official resolution before updating openradar.


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!