Skip to content

Fix #1286: Warn on inexistent imports that are not used. #1479

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

Merged
merged 1 commit into from
Oct 21, 2016

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@smarter
Copy link
Member

smarter commented Aug 26, 2016

Shouldn't this be an error instead of a warning?

@nicolasstucki
Copy link
Contributor Author

Given that they can be safely ignored without any semantic issue, it seemed that a warning was the reasonable choice.

case tree: Import =>
val exprTpe = tree.expr.tpe
tree.selectors.foreach {
case ident @ Ident(name) if name != nme.WILDCARD && !exprTpe.member(name).exists =>
Copy link
Contributor

Choose a reason for hiding this comment

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

You can factor our the common code in a helper function checkExists(name).

@nicolasstucki
Copy link
Contributor Author

All comments have been addressed.

@stuhood
Copy link

stuhood commented Sep 9, 2016

It is very handy for this check to differentiate between used and unused, thanks! But I agree with @smarter that it should be an error.

case Import(expr, selectors) =>
val exprTpe = expr.tpe
def notExists(name: Name): Boolean =
name != nme.WILDCARD && !exprTpe.member(name).exists
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to refine this so that you look for term names and for type names.

I also agree that it should be an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it emits an error and it tests the name as a type name as well.

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 also made it encode the name. This was needed for example in scala.collections.immutable.::.

@@ -4,6 +4,16 @@ object language {

class Feature

/** Enable scala.Dynamic */
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave everything in scala.language? My latest PR #1550 removed dotty.language completely.

Otherwise LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change on #1550 will break this PR. I will have to find another way to handle the members in the language module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I would propose to have them all in scala.language, not dotty.language.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased on #1550 and made changes to find all language features in scala.language.

val exprTpe = expr.tpe
def checkIdent(ident: Ident): Unit = {
val name = ident.name.asTermName.encode
def isDottyLanguageFeature = { // TODO Add new language features to scala.language
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make an exception for language features? I would doubt we need one, but if we do, this needs to be explained in a comment.

@odersky
Copy link
Contributor

odersky commented Oct 16, 2016

Resolved that we need to solve the dotty language module issue (i.e. that it differs from scalac's) as part of this pull request.

@nicolasstucki nicolasstucki force-pushed the fix-#1286 branch 4 times, most recently from ac33252 to 1b52452 Compare October 20, 2016 15:49
@nicolasstucki
Copy link
Contributor Author

#1617 fixed the issue with the language module. This PR will probably need a rebase on #1617.

@nicolasstucki
Copy link
Contributor Author

Rebased. No longer depends on dotty.language.

@odersky odersky merged commit b008ceb into scala:master Oct 21, 2016
@allanrenucci allanrenucci deleted the fix-#1286 branch December 14, 2017 16:59
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.

4 participants