EXC_BAD_ACCESS recursion crash called by protocol property

Originator:rupert
Number:rdar://22685592 Date Originated:14/09/2015
Status:Open Resolved:
Product:Developer Tools Product Version:7A218
Classification: Reproducible:Always
 
Summary:
Accessing a sub-property on a protocol-typed property of a class causes the `didSet` for that property to be called, leading to an EXC_BAD_ACCESS crash if anything in the `didSet` closure causes it to be accessed again.

Steps to Reproduce:
Simply use the following code in a playground:

protocol Bob {
	var name: String { get }
}

class Bobby: Bob {
	let name: String = "Bob"
}

class Fred {
	var viewModel: Bob {
		didSet {
			print("setter")
			self.bind()
		}
	}
	
	init(viewModel: Bob) {
		self.viewModel = viewModel
		self.bind()
	}
	
	func bind() -> Void {
		print("vm name is \(self.viewModel.name)")
	}
}

let vm: Bobby = Bobby()
let fred: Fred = Fred(viewModel: vm)

Expected Results:
The console should simply log "my name is Bob"

Actual Results:
The console goes into a never-ending loop eventually causing an EXC_BAD_ACCESS crash

Version:
Xcode 7A218 on OS X 10.10.5 (14F27)

Notes:
If, in the protocol defined above, we add the `class` restriction then this no longer causes a crash, which would seem to imply that accessing the property's sub-property is seen as causing the property to mutate.

Configuration:
MacBookPro11,1

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!