Show parameter type in -Wunused:params warnings#10014
Closed
benrbray wants to merge 1 commit intoscala:2.13.xfrom
Closed
Show parameter type in -Wunused:params warnings#10014benrbray wants to merge 1 commit intoscala:2.13.xfrom
-Wunused:params warnings#10014benrbray wants to merge 1 commit intoscala:2.13.xfrom
Conversation
benrbray
commented
Apr 24, 2022
| ) | ||
| for (s <- unusedPrivates.unusedParams if warnable(s)) | ||
| emitUnusedWarning(s.pos, s"parameter $s in ${if (s.owner.isAnonymousFunction) "anonymous function" else s.owner} is never used", WarningCategory.UnusedParams, s) | ||
| emitUnusedWarning(s.pos, s"parameter $s in ${if (s.owner.isAnonymousFunction) "anonymous function" else s.owner} is never used\nType: ${s.tpe.toLongString}", WarningCategory.UnusedParams, s) |
Author
There was a problem hiding this comment.
is toLongString the best way to show complete type information here? or nameAndArgsString?
Contributor
|
I fixed the position in #10015 and then also included different words for evidence. I'm not sure the extra info in the message is necessary, but it probably could not hurt. |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I recently filed scalameta/metals-feature-requests#270 and learned that the unused parameter warnings in Metals are forwarded from
scalac. I realized it would only be a relatively minor change to the compiler, so I'd like to get the ball rolling with this PR.Problem
Currently, unused named parameters give the following warning. The type is not shown, but having the name available makes it easy to figure out which parameter is unused.
However, when using context bounds, implicit arguments have auto-generated names like
evidence$1, making it difficult to identify the steps needed to resolve the warning, especially in cases where there are several type parameters each with their own context bounds.Proposed Solution
Warning messages generated by
-Wunused:paramsshould include both the name AND type of the unused parameter. For example,Alternatives
Without these more descriptive error messages, the only way to identify the source of an
unused evidence$nwarning is to count up to thenth context bound in the method signature.In certain cases, the squiggly red/yellow underline will be drawn directly under the unused context bound, making it easy to see which context bound is unused. However, in some cases it will be drawn under the method name itself (which is probably a bug, although I was not able to reproduce it for my simple example).
Questions
-Wunusedwarnings be updated to show type information as well?I'm happy to do the work on this after receiving some guidance on the above.
Todos