title: Scala pattern matching with Option type
body: <p>I am trying to define a binary tree with the following definition:</p>
  
  <pre><code>  trait Node {
      val label: Int
    }
    case class BranchNode(override val label: Int, left: Option[Node], right: Option[Node]) extends Node
    case class LeafNode(override val label: Int) extends Node
  </code></pre>
  
  <p>and then define a simple <code>printTree</code> method using Scala's pattern matching as below:</p>
  
  <pre><code>  def printTree(aTree: Option[Node]): Unit = aTree match {
      case None =&gt; print(".")
      case Some(LeafNode(label)) =&gt; print(label)
      case Some(BranchNode(label, left, right)) =&gt; "{" + printTree(left) + label + printTree(right) + "}"
    }
  </code></pre>
  
  <p>The Intellij IDE warns me that the match may not be exhaustive. An <code>Option</code> can have <code>None</code> or <code>Some</code> as it's values. In case of <code>Option[Node]</code>, it can either be <code>Some(LeafNode)</code> or <code>Some(BranchNode)</code>. What other cases am I overlooking?</p>