Created
December 29, 2014 20:32
-
-
Save neonichu/e764ad902caead0176f9 to your computer and use it in GitHub Desktop.
WTF Swift generics?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env xcrun swift | |
import Foundation | |
class Base { | |
} | |
class Sub : Base { | |
} | |
func create<T : Base>() -> T { | |
println("param is: " + NSStringFromClass(T)) | |
return T() | |
} | |
let o1: Sub = create() | |
println("result is: " + NSStringFromClass(o1.dynamicType)) |
maybe it isn't until it needs to be? the type is dynamic?
FWIW
let o2: Sub = Base()
correctly leads to
error: 'Base' is not convertible to 'Sub'
Submitted as a radar: http://www.openradar.me/19357437
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result should also be of type
Sub
, shouldn't it?