Skip to content

Instantly share code, notes, and snippets.

@marciok
Created November 28, 2016 19:12
Show Gist options
  • Select an option

  • Save marciok/347c00b57b6c41667966cb1a0a9f6650 to your computer and use it in GitHub Desktop.

Select an option

Save marciok/347c00b57b6c41667966cb1a0a9f6650 to your computer and use it in GitHub Desktop.
Is that a bug? πŸ€”
// It seems like Swift cannot correctly infer the type on the *second element* of the expression
func postOrder(_ node: Node?) -> [Int] {
guard let node = node else { return [] }
return [node.content] + postOrder(node.left) + postOrder(node.right) // ❌ ERROR: 'Int' is not convertible to [Int]
}
// If I specify than it works...
func postOrder(_ node: Node?) -> [Int] {
guard let node = node else { return [] }
return [node.content] + postOrder(node.left) + (postOrder(node.right) as [Int]) // βœ… That works
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment