2012-10-06 3 views
3

누군가 삭제 경고를주는 이유를 설명 할 수 있습니까?스칼라 스트림 삭제 경고

warning: non variable type-argument A in type pattern scala.collection.immutable.Stream[A] is unchecked since it is eliminated by erasure 
      case head #:: _ => Some(head) 

은 내가 경고를 얻을이 경우 if (x.isInstanceOf[Stream[_]]) ...를 작성하고 수 없습니다 실현,하지만 내 경우에는 내가 실제로 패턴 매칭을 사용하려는 경고의 모두 내가 돈을 갖는

def optionStreamHead(x: Any) = 
    x match { 
    case head #:: _ => Some(head) 
    case _ => None 
    } 

을 제공합니다 t 이해 '나쁜

보인다 그리고 여기에 동등하게 수수께끼 사건 :

type IsStream = Stream[_] 

("test": Any) match { 
    case _: Stream[_] => 1 // no warning 
    case _: IsStream => 2 // type erasure warning 
    case _ => 3 
} 

답변

3

두 가지 모두 2.9의 버그이며 2.10에서 해결되었습니다. 2.10에서 우리는 새로운 패턴 매칭 엔진 (가상 패턴 매처를위한 virtpatmat)을 얻습니다.

scala> def optionStreamHead(x: Any) = 
    x match { 
    case head #:: _ => Some(head) 
    case _ => None 
    } 
optionStreamHead: (x: Any)Option[Any] 

scala> optionStreamHead(0 #:: Stream.empty) 
res14: Option[Any] = Some(0) 

scala> ("test": Any) match { 
    | case _: Stream[_] => 1 // no warning 
    | case _: IsStream => 2 // type erasure warning 
    | case _ => 3 
    | } 
<console>:11: warning: unreachable code 
       case _: IsStream => 2 // type erasure warning 
            ^
res0: Int = 3 
+0

두 번째 예제는 스칼라 버그입니까? – Heptic

+0

@Heptic : 죄송합니다. 간과 했음에 틀림 없습니다. 나는 내 대답을 편집했다. – sschaef