0

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

    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

如何忽略这些警告?

4

0 回答 0