Swift: Non-generic subclass of generic class does not pass argument properly?

Originator:joshaber
Number:rdar://18701780 Date Originated:10/19/14
Status:Open Resolved:
Product:Developer Tools Product Version:6.1 (6A1046a)
Classification:Serious Bug Reproducible:Always
 
This is a weird one but I finally found the reproduction steps. Just check out the example below.

Steps to Reproduce:
// Playground - noun: a place where people can play

import Cocoa

class GeneralThing<S> {
	var stuff: S?

	func doIt() {
		if let s = stuff {
			doWithStuff(s)
		}
	}

	func doWithStuff(stuff: S) -> S {
		return stuff
	}
}

class SpecificThing<T>: GeneralThing<Int> {
	override func doWithStuff(stuff: Int) -> Int {
		println("\(stuff + 1)")
		return stuff + 1
	}
}

let t = SpecificThing<Float>()
t.stuff = 1
t.doIt()


Expected Results:
Should print "2" and return 2.

Actual Results:
In a playground it seems to (usually) crash. Though not always. The `stuff` argument passed to `SpecificThing.doWithStuff` seems to be garbage.

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!