diff options
author | simonpj@microsoft.com <unknown> | 2010-04-12 15:16:30 +0000 |
---|---|---|
committer | simonpj@microsoft.com <unknown> | 2010-04-12 15:16:30 +0000 |
commit | 54e73a90c275713c3804239fe61fbd5208cee60f (patch) | |
tree | 687bb9be6d59cfdf30080718affc8a70730c0b9c /compiler/rename/RnPat.lhs | |
parent | 6ddc8fd8b4952a23d1016dbad4263b89b63c5ae3 (diff) | |
download | haskell-54e73a90c275713c3804239fe61fbd5208cee60f.tar.gz |
Fix Trac #3943: incorrect unused-variable warning
In fixing this I did the usual little bit of refactoring
Diffstat (limited to 'compiler/rename/RnPat.lhs')
-rw-r--r-- | compiler/rename/RnPat.lhs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.lhs index 813f39b8a1..58c2c34373 100644 --- a/compiler/rename/RnPat.lhs +++ b/compiler/rename/RnPat.lhs @@ -167,10 +167,12 @@ newName (LetMk mb_top fix_env) rdr_name do { name <- case mb_top of Nothing -> newLocalBndrRn rdr_name Just mod -> newTopSrcBinder mod rdr_name - ; bindLocalNamesFV_WithFixities [name] fix_env $ + ; bindLocalName name $ -- Do *not* use bindLocalNameFV here + -- See Note [View pattern usage] + addLocalFixities fix_env [name] $ thing_inside name }) - -- Note: the bindLocalNamesFV_WithFixities is somewhat suspicious + -- Note: the bindLocalName is somewhat suspicious -- because it binds a top-level name as a local name. -- however, this binding seems to work, and it only exists for -- the duration of the patterns and the continuation; @@ -178,6 +180,14 @@ newName (LetMk mb_top fix_env) rdr_name -- before going on to the RHSes (see RnSource.lhs). \end{code} +Note [View pattern usage] +~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + let (r, (r -> x)) = x in ... +Here the pattern binds 'r', and then uses it *only* in the view pattern. +We want to "see" this use, and in let-bindings we collect all uses and +report unused variables at the binding level. So we must use bindLocalName +here, *not* bindLocalNameFV. Trac #3943. %********************************************************* %* * |