2015-06-03 50 views
0

下面的代碼編譯器警告生成此編譯警告:一個重複的情況下的參數或提取的序列應通過序列通配符(_ *)如何固定在scala.xml.Elem

import scala.xml.Elem 
def matchElem(e: Elem) = e match { case <source/> => "match!" } 

僅匹配如何修復?

+0

https://開頭的問題。 scala-lang.org/browse/SI-9343 –

回答

3

您可以使用scalac -Xlint:-stars-align,_來取消警告,該警告用於this issue

你的函數看起來像-Xprint:typer

 def matchElem(e: scala.xml.Elem): String = e match { 
      case scala.xml.Elem.unapplySeq(<unapply-selector>) <unapply> (_, "source", _, _) => "match!" 
     } 

要回答你的問題:

$ scala -Xlint 
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45). 
Type in expressions to have them evaluated. 
Type :help for more information. 

scala> import xml._ 
import xml._ 

scala> def matchElem(e: Elem) = e match { case Elem(_, "source", _, _, _*) => "match!" } 
matchElem: (e: scala.xml.Elem)String 

或圖案嵌入序列通配符:

scala> <a/> match { case <a/> => } 
<console>:8: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). 
     <a/> match { case <a/> => } 
         ^

scala> <a/> match { case <a>{ ns @ _* }</a> if ns.isEmpty => }