-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Shouldn't this be an error instead of a warning? |
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 => |
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.
You can factor our the common code in a helper function checkExists(name)
.
5d5bc61
to
c738655
Compare
5d5bc61
to
9d24628
Compare
All comments have been addressed. |
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 |
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.
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.
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.
Now it emits an error and it tests the name as a type name as well.
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.
I also made it encode the name. This was needed for example in scala.collections.immutable.::
.
9d24628
to
36a3a8f
Compare
@@ -4,6 +4,16 @@ object language { | |||
|
|||
class Feature | |||
|
|||
/** Enable scala.Dynamic */ |
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.
Can we leave everything in scala.language? My latest PR #1550 removed dotty.language completely.
Otherwise LGTM
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 change on #1550 will break this PR. I will have to find another way to handle the members in the language module.
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.
Yes, I would propose to have them all in scala.language, not dotty.language.
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.
Rebased on #1550 and made changes to find all language features in scala.language
.
36a3a8f
to
f97da2d
Compare
f97da2d
to
0964f07
Compare
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 |
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.
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.
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. |
ac33252
to
1b52452
Compare
This commit also fixes scala#1583.
1b52452
to
a8136ff
Compare
Rebased. No longer depends on |
No description provided.