Skip to content

Comments

Unused var tweaks#4088

Merged
rhendric merged 5 commits intopurescript:masterfrom
nwolverson:unused-var-tweaks
May 12, 2021
Merged

Unused var tweaks#4088
rhendric merged 5 commits intopurescript:masterfrom
nwolverson:unused-var-tweaks

Conversation

@nwolverson
Copy link
Contributor

@nwolverson nwolverson commented May 11, 2021

Improvements to unused variable lint/warnings.

Fix a bad unused variable warning (fix #4083). The previous iteration was not distinguishing between variables bound recursively within the let binding, and those that are only bound inside the body.

Unchanged with this commit is that identifiers which are used recursively within a let binding will count as used (ie not warn), despite the fact that the binding could be removed - something more intelligent would be required to handle mutually recursive let blocks which may or may not be used externally.

Tighten the warning spans on unused variables (fix #4087).

This will scope to the identifier itself for binders, but a value declaration let x = e in e2 will scope to the entire x = e as ValueDecl does not have a source span for the identifier alone.

Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

removeAndWarn ss newNames (used, errors) =
let filteredUsed = used `S.difference` newNames
removeAndWarn :: SourceSpan -> S.Set (SourceSpan, Ident) -> (S.Set Ident, MultipleErrors) -> (S.Set Ident, MultipleErrors)
removeAndWarn _ newNamesWithSpans (used, errors) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep the _?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I have a short attention span?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh there is so much noise floating around due to this :)

Copy link
Member

@rhendric rhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cosmetic fixes and then LGTM.

allExprs = concatMap unguard gexprs
in
removeAndWarn ss bindNewNames $ mconcat $ map (go ss) allExprs
removeAndWarn bindNewNames $ mconcat $ map (go) allExprs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded parens in (go). (I found four of these in total; they're easy to search for.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dear, a little bit naive on the search and replace :)

in removeAndWarn letNewNamesRec $
mconcat (map underDecl ds)
<> removeAndWarn letNewNames (doElts rest v)
doElts (PositionedDoNotationElement _ _ e : rest) v = doElts (e : rest) v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space in the RHS here.

@rhendric
Copy link
Member

Oh sorry, would you add a CHANGELOG.md entry for this too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unused variable warnings in case binders point to span for entire case expression Incorrect unused variable warning

3 participants