Using computed property in Swift extension crashes compiler

Originator:mail
Number:rdar://17254507 Date Originated:2014-06-10
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6 beta 1
Classification:Serious Bug Reproducible:Always
 
Summary:
When declaring a computed property inside an extension on an Obj-C class in one Swift source file, trying to use it from another Swift file crashes the compiler.

Steps to Reproduce:
1. Create an Obj-C project using Obj-C as the language (Sprite Kit game template for iOS)
2. Add a Swift file to the project. Let Xcode make bridging header.
3. Add the following to the Swift file:

import SpriteKit

extension SKNode {
  var scaleAsPoint: CGPoint {
    get {
      return CGPoint(x: self.xScale, y: self.yScale)
    }
    set {
      self.xScale = newValue.x
      self.yScale = newValue.y
    }
  }
}

This creates a computed property on SKNode that lets you treat the node's scale as single a CGPoint value.

4. In one of the .m files, do:

#import "Swift2ObjCBug-Swift.h"

And try to print out the scale of a node using the new computed property:

NSLog(@"Node scale = %@", NSStringFromCGPoint(myLabel.scaleAsPoint));

5. Run the app. This works.
6. Add a new Swift file to the project. Give it the following contents:

import SpriteKit

func whatever() {
  let node = SKNode()
  println("Scale is \(node.scaleAsPoint)")
}

7. Build the project. The build will fail because Xcode can no longer find Swift2ObjCBug-Swift.h


Expected Results:
The build should not fail. Both the Obj-C and Swift code should be able to access node's new scaleAsPoint property.

Actual Results:
The build fails. The reason Xcode can no longer find Swift2ObjCBug-Swift.h is because the Swift compilation phase is aborted and the header file does not get written.

The crash from the compiler is:

0  swift                    0x000000010493d608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x000000010493daf4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff8a9b35aa _sigtramp + 26
3  libsystem_platform.dylib 0x00007ffaea92f0c0 _sigtramp + 1610070832
4  swift                    0x0000000103d47995 swift::irgen::ClassMetadataLayout<(anonymous namespace)::FindClassMethodIndex>::addClassMembers(swift::ClassDecl*) + 37
5  swift                    0x0000000103d417b2 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ResilienceExpansion) + 434
6  swift                    0x0000000103dad0d3 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 42611
7  swift                    0x0000000103da2266 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8678
8  swift                    0x0000000103d236f8 swift::irgen::IRGenModule::emitGlobalTopLevel() + 184
9  swift                    0x0000000103d8f6e3 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1859
10 swift                    0x0000000103d90033 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
11 swift                    0x0000000103d0265a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4842
12 swift                    0x0000000103d0135d main + 1533
13 libdyld.dylib            0x00007fff92bc05fd start + 1
14 libdyld.dylib            0x0000000000000037 start + 1833171515
0.  Program arguments: <snipped>
1.	While emitting IR SIL function @_TF13Swift2ObjCBug8whateverFT_T_ for 'whatever' at /Users/matthijs/Desktop/Swift2ObjCBug/Swift2ObjCBug/OtherSwiftFile.swift:11:1
<unknown>:0: error: unable to execute command: Segmentation fault: 11


Version:
Xcode 6 beta 1 / OS X 10.9.3


Notes:
The compiler does not crash when you add the code that uses node.scaleAsPoint to the same Swift file that declared the computed property. But as soon as it goes into another Swift file, the crash occurs.

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!