Last active
December 3, 2015 14:28
-
-
Save dhogborg/d22197ffac691f8f7fd8 to your computer and use it in GitHub Desktop.
Cryptic swiftc error
This file contains 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
/** | |
## Cryptic swiftc error | |
This bit of code is flawed, and the swift compiler gives a really unhelpful | |
error message. | |
XCode and Playgrounds thinks this is valid code. Not until swiftc | |
try to compile it the error is discovered. And at that point it's | |
not clear where the error is located as XCode does not give any | |
more information than the comment below. | |
*/ | |
import UIKit | |
protocol ChildProt : class { | |
init() | |
func name() -> String | |
} | |
class Parent { | |
required init() { | |
} | |
static func queryChildren() -> [ChildProt] { | |
// don't try to check a protocol adherence of self in a static function | |
guard let prot = self as? ChildProt else { | |
preconditionFailure() | |
} | |
return [prot.dynamicType.init()] | |
} | |
} | |
class Child : Parent, ChildProt { | |
var NAME = "John Doe" | |
required init() { | |
} | |
func name() -> String { | |
return self.NAME | |
} | |
} | |
let child = Child.queryChildren().first! | |
child.name() | |
// This is the error message procuded by XCode. | |
// | |
// Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1 | |
// | |
// PHI nodes must have at least one entry. If the block is dead, the PHI should be removed! | |
// %50 = phi i8** , !dbg !530 | |
// LLVM ERROR: Broken function found, compilation aborted! | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment