-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fix compiler warnings #258
Conversation
This is so great @wlk 😄! Let us know when this is ready, you probably want to squash all the commits since the previous ones were failing. That way, we make sure that commits pass build 👍 |
a4c8f6d
to
b86033e
Compare
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.
Thank you for spending time on this @wlk!
I have a few questions / requested changes, but other than that this looks good.
Welcome to Zinc.
.gitignore
Outdated
@@ -1,2 +1,3 @@ | |||
target/ | |||
zinc/src/test/resources/bin | |||
.idea |
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.
If you are an IntelliJ IDEA user I would suggest you configure your global gitignore file, instead of expecting every project to include these ignores or adding them while submitting a pull request.
GitHub has a nice little help article about it: https://help.github.com/articles/ignoring-files/.
The general principle is that .gitignore should only include paths for files that are generated by running the build, and not include a random assortment of paths generated by other tools.
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.
no problem
@@ -162,6 +162,7 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) ext | |||
def usedNameInImportSelector(name: Name): Unit = { | |||
if (!isEmptyName(name) && (name != nme.WILDCARD) && !names.contains(name)) { | |||
names += name | |||
() |
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.
Just out of my own curiosity, could you explain this change?
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.
There is a warning discarded non-Unit value
I followed the suggestion from here: http://stackoverflow.com/questions/13415307/suppress-discarded-non-unit-value-warning (also saw this pattern in few other places in code)
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.
Oh discarded inside the if block, of course. Thanks.
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.
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.
No, value discarding is a real source of error, particularly with side-effecting (such as mutating) code.
One way to deal though with this is to explicitly discard the unused value. Either as a method or as an extension method (e.g .toUnit), and then the method could document its reason for existence.
The real solution is to change the compiler so -Ywarn-value-discard doesn't warn about this.type. Then you'll fix it for all codebases :-)
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 vote in favor of removing that warning. IMO it's unnecessary. I generally think that this codebases abuses warnings. The same goes for unused imports.
I don't see why this is a real source of error. I have never experienced it.
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 disagree with unused imports since later on we are left with tons on unused imports. However we don't need to apply it to all compilations - IMO we can apply it only for CIs builds (since hacking with fatal unused imports is not pleasant).
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 the compiler warnings do help with keeping the code more maintainable (assuming you change code to prevent warnings), so IMO both warnings could be left in as they are, maybe -Ywarn-value-discard
is a little to verbose but that's not a big deal.
} | ||
def apply(a: ClassLike, b: ClassLike): Boolean = { | ||
new SameAPI(false, true).check(a, b) | ||
} |
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.
Could you drop the brackets and one-line this please? Looks short enough.
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.
fixed
source <- guessSourcePath(sourceMap, classFile, log); | ||
binaryClassName = classFile.className; | ||
loadedClass <- load(binaryClassName, Some("Error reading API from class file")) | ||
) { | ||
binaryClassNameToLoadedClass.update(binaryClassName, loadedClass) | ||
val srcClassName = binaryToSourceName(loadedClass) | ||
val maybeSrcClassName = binaryToSourceName(loadedClass) |
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 don't see the need for the Hungarian notation. I prefer the former.
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.
No problem, I did this because few lines below we are reusing name srcClassName
inside match
-> I renamed the value inside the match to avoid confustion
classNames += srcClassName | ||
case Some(className) => | ||
analysis.generatedNonLocalClass(source, newClass, binaryClassName, className) | ||
classNames += className |
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.
One of the wonderful things about pattern matching (in my opinion) is the ability to shadow.
Was this change triggered by a warning? If so, what was the warning about? And who emitted it?
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.
Good observation, this was warning generated by intellij "Suspicious shadowing by a Variable Pattern". I don't have strong opinion how to approach this but usually I try to avoid shadowing by using different names
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.
Ah right, yeah I have that inspection turned off. This is its motivation:
Detects a Variable Pattern that shadows a stable identifier defined in the enclosing scope. To perform an equality test against that value, use backticks.
Before:
val foo = 0 0 match { case foo => }After:
val foo = 0 0 match { case `foo` => }
Food for thought :-)
Approved, pending Travis CI building it successfully obviously. |
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.
LGTM!
One minor suggestion: squash all the commits 😄. Let's merge when CI passes.
You're getting
in the 2.11 build. And a whole lot of errors in the 2.12 build. |
@dwijnand I'll have more time to look at this tomorrow, most likely I have removed import that is reported as unused, but is in fact used (I have already stumbled on few cases like this here) |
Indeed, this happens because Intellij knows that you're using a concrete Scala version. The issue is that we use implicits for compatibility reasons, so that if a method is not defined in a class the compiler automatically tries to get an implicit class with that method. We use this to keep track of changes in the Scala compiler API. That, mixed with some false positives from Intellij sides, may be the culprit of this. Double check that the removed imports are indeed used and you're good to go. Looking forward to merge this and remove all this clutter from my screen 👍 |
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.
Good stuff! Finally someone was brave enough to clean up the code :)
Except to minor rewrites (that are consequence of cleanup) LGTM
@@ -24,9 +24,9 @@ object ClassToAPI { | |||
// (api, public inherited classes) | |||
def process(classes: Seq[Class[_]]): (Seq[api.ClassLike], Set[(Class[_], Class[_])]) = | |||
{ | |||
val pkgs = packages(classes).map(p => new api.Package(p)) | |||
packages(classes).map(p => new api.Package(p)) |
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.
If we really don't use return values we should replace map
and flatMap
with foreach
(and remove overhead for creating unused collections).
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.
Agreed 😄
@@ -73,14 +73,14 @@ final class LocalJavadoc() extends XJavadoc { | |||
override def run(sources: Array[File], options: Array[String], incToolOptions: IncToolOptions, | |||
reporter: Reporter, log: XLogger): Boolean = { | |||
val cwd = new File(new File(".").getAbsolutePath).getCanonicalFile | |||
val (jArgs, nonJArgs) = options.partition(_.startsWith("-J")) | |||
val (_, nonJArgs) = options.partition(_.startsWith("-J")) |
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.
If we care only about 'false' part of partition
we should use filterNot
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.
Agreed 👍
292e27e
to
5460ff4
Compare
2a19103
to
b09d79f
Compare
Commits squashed and travis should report green status in a moment. The warnings I didn't change are related to scaladoc and few deprecation warnings |
b09d79f
to
63695f4
Compare
Avoid empty generators when possible (take 2)
I noticed that there are a lot of compiler warnings during build, this PR attempts to fix (a large) portion of them: