title: Pattern Matching casting
body: <p>I have external service which returns AnyRef I want to cast result to Boolean, or return false if return is not Boolean.</p>
  
  <p>Here is a example:</p>
  
  <pre><code>object ExternalService {
  
    def sendEvent(s: String) : AnyRef = {
      return true   } 
    }
  
  object Caller {
  
    def isValid(s: String): Boolean = {
  
      val value = ExternalService.sendEvent("test")
      value match {
        // pattern type is incompatible with expected type found Boolean expected AnyRef
        case b: Boolean =&gt; b
        case _ =&gt; false
      }   
    } 
  }
  </code></pre>
  
  <p>but i got</p>
  
  <blockquote>
    <p>Error:(6, 12) the result type of an implicit conversion must be more
    specific than AnyRef
        return true; Error:(6, 12) type mismatch;  found   : Boolean(true)  required: AnyRef
        return true; Error:(17, 15) pattern type is incompatible with expected type;  found   : Boolean  required: Object
          case b: Boolean => b</p>
  </blockquote>
  
  <p>How can I cast AnyRef to Boolean in this case or in general? </p>