diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-09-14 23:55:16 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2017-03-11 23:38:08 -0800 |
commit | f672aff3f3b92506741b62d8f7eae6d1e0dc36a7 (patch) | |
tree | 7bfacf173c601643e83a91bb5eb53fce9e0caf5e /src/compiler/scala/tools/nsc/ast | |
parent | 9d9abffc94b28785e54bc2179b495d81f29b1e7f (diff) | |
download | scala-f672aff3f3b92506741b62d8f7eae6d1e0dc36a7.tar.gz scala-f672aff3f3b92506741b62d8f7eae6d1e0dc36a7.tar.bz2 scala-f672aff3f3b92506741b62d8f7eae6d1e0dc36a7.zip |
SI-8040 Warn unused pattern vars
Warn for unused `case X(x) =>` but, as an escape hatch,
not for `case X(x @ _) =>`. The latter form is deemed
documentary. (Named args could serve a similar purpose,
`case X(x = _) =>`.)
An attachment is used to mark the bound var, and the
symbol position is used to correlate the identifier
with the variable that is introduced. This mechanism
doesn't work yet when only a single var is defined.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 0cdba861a5..dabce69b2f 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1957,7 +1957,14 @@ self => pattern3() case Ident(name) => in.nextToken() - atPos(p.pos.start) { Bind(name, pattern3()) } + val body = pattern3() + atPos(p.pos.start, p.pos.start, body.pos.end) { + val t = Bind(name, body) + body match { + case Ident(nme.WILDCARD) => t updateAttachment AtBoundIdentifierAttachment + case _ => t + } + } case _ => p } } |