如何忽略准引号中未使用的警告?



我有一个使用准引号的宏,如:

accessor.tree match {
// FIXME: Get rid of the unused warning here.
case q"($source) => $rhs" => validate(rhs, hasSelect = false)
case t                    => c.abort(c.enclosingPosition, s"Invalid function expression ${show(t)}")
}

这会给我以下警告:

[warn] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:12: pattern var qq$macro$1 in method unapply is never used: use a wildcard `_` or suppress this warning with `qq$macro$1@_`
[warn]       case q"($source) => $rhs" => validate(rhs, hasSelect = false)
[warn]            ^
[warn] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:16: pattern var source in method validateSelection is never used: use a wildcard `_` or suppress this warning with `source@_`
[warn]       case q"($source) => $rhs" => validate(rhs, hasSelect = false)
[warn]                ^
[warn] two warnings found

通配符不能用:

accessor.tree match {
// FIXME: Get rid of the unused warning here.
case q"(_) => $rhs" => validate(rhs, hasSelect = false)
case t              => c.abort(c.enclosingPosition, s"Invalid function expression ${show(t)}")
}

[error] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:18: ';' expected but '=>' found.
[error]       case q"(_) => $rhs" => validate(rhs, hasSelect = false)
[error]                  ^
[error] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:12: extractor macros can only expand into extractor calls
[error]       case q"(_) => $rhs" => validate(rhs, hasSelect = false)
[error]            ^
[error] two errors found

我不知道suppress this warning with `source@_`是什么意思

如果我从字面上理解为:

accessor.tree match {
// FIXME: Get rid of the unused warning here.
case q"(source@_) => $rhs" => validate(rhs, hasSelect = false)
case t                     => c.abort(c.enclosingPosition, s"Invalid function expression ${show(t)}")
}

得到:

[error] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:21: ')' expected but '@' found.
[error]       case q"(source@_) => $rhs" => validate(rhs, hasSelect = false)
[error]                     ^
[error] /Users/jason/source/goodcover/core/macros/src/main/scala/webm/react/syntax/StableFieldOpsImpl.scala:36:12: extractor macros can only expand into extractor calls
[error]       case q"(source@_) => $rhs" => validate(rhs, hasSelect = false)
[error]            ^
[error] two errors found

如何忽略这些警告?

不知道为什么,但添加

scalacOptions += "-Ywarn-macros:after"

使警告在我的例子中消失。

相关内容

  • 没有找到相关文章

最新更新