Skip to content

SI-9383 Improved unused import warning#4616

Merged
SethTisue merged 2 commits intoscala:2.12.xfrom
som-snytt:issue/9383
Jul 20, 2015
Merged

SI-9383 Improved unused import warning#4616
SethTisue merged 2 commits intoscala:2.12.xfrom
som-snytt:issue/9383

Conversation

@som-snytt
Copy link
Contributor

Previously, implicit search would mark every import
it touched as a lookup.

Instead, let subsequent type check perform the lookup.

Previously, implicit search would mark every import
it touched as a lookup.

Instead, let subsequent type check perform the lookup.
@scala-jenkins scala-jenkins added this to the 2.12.0-M3 milestone Jul 9, 2015
@SethTisue
Copy link
Member

@mrerrormessage (who found/reported the bug), maybe you could help review the test cases?

@som-snytt
Copy link
Contributor Author

I can't believe I got to fix an error message for @mrerrormessage! That's like scrubbing the kitchen floor and Mr Clean walks in. Now I understand why the people in those commercials look so happy.

@mrerrormessage
Copy link

This definitely solves my case, and looks pretty thorough. The only case I can think of that isn't explicitly covered (although I don't know enough to know whether it ends up being covered anyhow) is the case where the implicit itself is not imported explicitly by the user a-la StringOps (and a handful of others as well). Thanks for the quick fix and this is another reason to look forward to scala 2.12!

@som-snytt
Copy link
Contributor Author

@mrerrormessage I commented on the ticket that it doesn't matter how implicit search was kicked off. The weird example was integer subtraction (of all things), because it's overloaded and overloading tries to convert between param types when deciding on a most specific alternative.

Actually, I'll add both examples to the test, the string.contains was puzzler-worthy if it weren't also bug-worthy. I used them for testing until I noticed the existing unit test.

@mrerrormessage
Copy link

Awesome. Thanks for fixing this!

Copy link
Member

Choose a reason for hiding this comment

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

so this method is only called from collectImplicitImports, in which case you want to have record = false. to me it seems a little bit more clear to push record = false out to the callsite within collectImplicitImports. the method name here (importedAccessibleSymbol) doesn't tell me why it should or should not record the import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that the two code paths (lookupImport which is a real import versus importedAccessibleSymbol which is just a query) could have been better delineated in the original code, maybe by naming it isThisSymbolAccessiblyImportableAskingForAFriend, but the facade method was clearly intended to reduce clutter (of only one extra parameter). So the question is whether the facade method should be removed, the def at L953 renamed, and endowed with default args, for its one call site. Meh.

Since the query never looks for explicit import and never records, the params shouldn't be pushed to the callsite.

The facade method avoids defaults which would never be specified.

@lrytz
Copy link
Member

lrytz commented Jul 16, 2015

the rest looks great!

Per review, adds a function that clarifies the purpose
of the code path that collects imported implicits,
namely, to examine qualifying imported implicits and
then collect them. In the context of doing something
with the import (besides importing), it's clear why we
don't want to record that we used the import, that is,
because we might be doing something other than using.

That's clear, right?
SethTisue added a commit that referenced this pull request Jul 20, 2015
SI-9383 Improved unused import warning
@SethTisue SethTisue merged commit f55bdbf into scala:2.12.x Jul 20, 2015
@SethTisue
Copy link
Member

thanks everybody, especially @som-snytt

@som-snytt
Copy link
Contributor Author

Was this the PR that got me sucked into -Wunused?

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.

6 participants