Skip to content

Instantly share code, notes, and snippets.

@dhogborg
Last active December 3, 2015 14:28
Show Gist options
  • Save dhogborg/d22197ffac691f8f7fd8 to your computer and use it in GitHub Desktop.
Save dhogborg/d22197ffac691f8f7fd8 to your computer and use it in GitHub Desktop.
Cryptic swiftc error
/**
## 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