title: scrutinee is incompatible with pattern type; found : package.SomeObject required: Unit
body: <p>I am trying a filesearcher program in scala.</p>
  
  <p>FileChecker.scala</p>
  
  <pre><code>package fileSearcher
  
  import sun.org.mozilla.javascript.internal.ast.Yield
  
  class FilterChecker(filter:String) {
  
  def matches(content: String) = content contains filter
  
  def findMatchedFiles(fileObjects: List[IOObject]) =
  
    for(fileObject &lt;- fileObjects
        if(fileObject.isInstanceOf[FileObject])
        if(matches(fileObject.name)))
      yield fileObject
  
  }
  
  object FilterChecker{
  
    def apply(filter: String)=new FilterChecker(filter)
  }
  </code></pre>
  
  <p>IOObject.scala</p>
  
  <pre><code>package fileSearcher
  import java.io.File
  trait IOObject {
    val file:File
    val name= file.getName()
  }
  
  case class FileObject(file: File)extends IOObject
  case class DirectoryObject(file: File)extends IOObject
  </code></pre>
  
  <p>FileConverter.scala</p>
  
  <pre><code>package fileSearcher
  
  import java.io.File
  
  object FileConverter {
  def convertToIOObject(file: File){
    if(file.isDirectory()) DirectoryObject(file)
    else FileObject(file)
  }
  }
  </code></pre>
  
  <p>Matcher.scala</p>
  
  <pre><code>package fileSearcher
  
  import java.io.File
  
  class Matcher(filter:String,rootLocation:String) {
  val rootIOObject=FileConverter.convertToIOObject(new File(rootLocation))
  
  def execute()={
    val matchedFiles= rootIOObject  match {
      case file : FileObject if FilterChecker(filter) matches file.name =&gt;List(file)  //error 1
      case directory: DirectoryObject =&gt; ???    //error 2
      case _ =&gt; List()
  
    }
    matchedFiles map(iOObject =&gt; iOObject.name) 
   }
  }
  </code></pre>
  
  <p>The above code gives me 2 error.</p>
  
  <pre><code>scrutinee is incompatible with pattern type; found : fileSearcher.FileObject required: Unit
  scrutinee is incompatible with pattern type; found : fileSearcher.DirectoryObject required: Unit
  </code></pre>
  
  <p>Can anybody explain me what I am doing wrong and how can I resolve it?</p>
  
  <p>Thanks</p>