Created
July 24, 2015 13:46
-
-
Save groue/2fbc11591794efa12fc6 to your computer and use it in GitHub Desktop.
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
// Library code | |
class Model { } | |
protocol Fetchable { | |
typealias FetchableType | |
static func fetchAll(sql: String) -> [FetchableType] | |
} | |
extension Fetchable where Self : Model, FetchableType == Self { | |
static func fetchAll(sql: String) -> [FetchableType] { | |
return [] // bare minimal, for demonstration purpose | |
} | |
} | |
// Userland code | |
class Parent: Model, Fetchable { | |
typealias FetchableType = Parent | |
} | |
class Child: Parent { | |
typealias FetchableType = Child | |
} | |
func f() { | |
let parents = Parent.fetchAll("SELECT * FROM ...") // [Parent] | |
// The line below makes the compiler crash. Comment it and the compiler is happy. | |
let children = Child.fetchAll("SELECT * FROM ...") // [Children] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not crash in a Playground.
Crashes in a regular swift file with