-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In selector check, prefix of reference must match import qualifier #20894
base: main
Are you sure you want to change the base?
Conversation
Further tweaks forthcoming. |
@som-snytt how much work do you think it still requires? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first commit is a bit suspicious, and might be the cause of the CI failures.
The second commit looks good and might pass more easily if submitted as an independent PR.
I'll submit commit 2 separately, as I was about to do except it's one line. I'll follow up the fix for commit 1 after the American holiday. |
634fdb0
to
741473e
Compare
The previous test fails were because the new prefix check (in I'll clean up and also look for improvements. |
aa1526f
to
b6c0fb6
Compare
09d418a
to
75d4d24
Compare
75d4d24
to
0f4be8a
Compare
Rebased and split out commits for easier review. This includes adding the prefix type to This is the July commit and not the August rewrite, which fixes scope bugs by leveraging normal miniphase traversal and avoiding the special traverser; which allows putting Example extra test fixed in August:
As the comment reminds me, it incorrectly detects the superconstructor ref as resolved by the nested import. Also note that the inner wildcard is not ambiguous because both imports resolve to the same symbol. But a further improvement would be to warn that the inner import is, if not unused, then spurious. Edit: redrafting to add the August rewrites. |
Cherry-picked some old commits. As a reminder to future self, the mega phase was broken because CheckShadowing sees the nested X as shadowing.
The fix [sic] is to ignore everything nested because it ignores constructor-owned X and M. [Previous attempt had been to short-circuit transformDeep so CheckShadowing doesn't see subtrees of "other" trees.] The fix [also sic] to superclass context noted in previous comment is also novel: since all the "context" approximation is for the purpose of import tracking, it doesn't need to capture all the subtlety of a true super class constructor context (with class parameters in scope). Instead, just detect that a reference occurred in a parent tree, and then kick it upstairs in popScope. The mechanism for tracking The "inner traverser" is removed in favor of matching "other" trees and transforming their parts. I see there was some long discussion about this. |
|
That is Thanksgiving Day shortly after the national election, of course. |
Don't hesitate to ping me when you would like me to take another look. I noticed you were still actively making changes, so I didn't pay attention to every push. |
eb1bf06
to
e8ca0cc
Compare
I see I was in the middle of adding commits a month ago and did not implement the speculation from my previous comment. My brain glazes over when I look at this PR. Also I have to re-read "getting started as a contributor" to understand "testing your changes". But I see this PR includes showing vulpix results more nicely. To reduce the heuristics which are dubious or less-strongly motivated, this reverts #16865 and warns in overrides. The original motivation in Scala 2 was that an override is constrained in its signature and shouldn't be required to use every parameter. Maybe that dates from before This keeps the "trivial method" heuristic: don't warn on
however, it ought to be possible to audit suppressed warnings (of all kinds and mechanisms). |
@sjrd thanks I have no love for this code or US politics, but this PR seems to address some functional issues. The PR embraces the miniphase API, but maybe that is the wrong direction. The phase is really a recheck: given context and scopes as at typer, it should track definitions and imports (things that introduce names) and usages. Per scope, it only needs to look up a reference once (to see if it is satisfied by a def or import). I could try that out as a follow-up to see if it is feasible. The weaknesses of the current approach are that it doesn't model scopes precisely and isn't efficient (references bubble up the stack, including uninteresting refs such as |
There are |
I didn't get around yet to handling constructor contexts when I worked around superconstructor contexts. #21917 Note to self: don't neglect secondary constructors, which are lexically nested but typechecked like primary ctor in outer context. |
ac3f5dc
to
52e229c
Compare
Prefer context functions for brevity. Avoid intermediate collections. Check scope type Use type test of prefix for usages in scope Style tweaks in CheckUnused Attachment tracks derivation No warn serialization methods Assume tpd
Filter member of refinement, handle Annotated TypeTree is usage of simple name Handle quotes and splices Tighten allowance for serialization methods Restore inferred type is not a usage, noprefix is in import Warn for top level private Import given takes NoPrefix usage Don't ignore params of public methods Accept updated semanticdb output
Handle match types No transparent inline exclusion
52e229c
to
9fac2ae
Compare
9fac2ae
to
e7422fa
Compare
This PR changes the
CheckUnused
phase to rely on theMiniPhase
API (instead of custom traversal). That improves fidelity toContext
(instead of approximate scoping).The phase should work seamlessly with subsequent linting phases (currently,
CheckShadowed
).It is a goal of the PR to eliminate false reports. It is also a goal not to regress previous work on efficiency.
A remaining limitation of the current approach is that contexts don't provide a nesting level. Practically, this means that for a wildcard import nested below a higher precedence named import, the wildcard is deemed "unused". (A more general tool for "managing" or "formatting" imports could do more to pick a preferred scope.)
This PR adds
-Wunused:patvars
, as forward-ported from Scala 2: it relies on attachments for some details about desugaring, but otherwise uses positions (where only the original patvar has a non-synthetic position).As in Scala 2, it does not warn about patvars with the "canonical" name of a case class element (this is complicated by type tests and the quotes API); other exclusions are to be ported, such as "name derived from the match selector".
Support is added for
-Wconf:origin=full.path.selector
, as in Scala 2. That allows, for example:to exclude certain blessed imports from warnings, or to work around false positives (should they arise).
Support is added to
-rewrite
unused imports. There are no options to "format"; instead, textual deletions preserve existing formatting, except that blank lines are removed and braces removed when there is only one selector.Notable fixes are to support
compiletime
andinline
; there are more fixes to pursue in this area.The commits are not organized around these changes; commits are preserved here just for comparison to previous art, so that useful existing behaviors do not regress.
Fixes #19657
Fixes #20520
Fixes #19998
Fixes #18313
Fixes #17371
Fixes #18708
Fixes #21917
Fixes #21420
Fixes #20951
Fixes #19252
Fixes #18289
Fixes #17667
Fixes #17252
Fixes #21807
Fixes #17753
Fixes #17318