Skip to content

Re-enable PluginCoverageScalaJsTest, fix dangling UndefinedParam bug #464

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 14 commits into from
Jun 3, 2022

Conversation

armanbilge
Copy link
Contributor

@armanbilge armanbilge commented May 31, 2022

This PR re-enables the PluginCoverageScalaJsTest that is currently being ignored. Fortunately, it still passes :)

Fixes #447.

@armanbilge
Copy link
Contributor Author

Strange, I could have sworn the test was passing before! But failure is good too, it might mean #447 is a regression and not a new issue.

Comment on lines -149 to +151
.dependsOn(runtimeJVM % Test)
// we need both runtimes compiled prior to running tests
.dependsOn(runtimeJVM % Test, runtimeJS % Test)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, it was some trickiness actually. No regression.

Copy link
Member

Choose a reason for hiding this comment

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

Ah this make sense. 👍🏼 good catch.

@armanbilge
Copy link
Contributor Author

Ok, this is ready for review :) I'll work on #447 in a follow-up PR.

@armanbilge
Copy link
Contributor Author

Actually, I am skeptical if this is invoking the compiler the right way yet. Partly because I can't reproduce #447, and also because I realized I didn't make any configuration changes besides adding the sjs compiler to the classpath, which surely won't activate it magically 😅

@armanbilge armanbilge marked this pull request as draft May 31, 2022 08:40
@armanbilge
Copy link
Contributor Author

Ok, I know I'm going in circles here, but now that I think I'm invoking the compiler correctly, indeed the existing test is broken with the same issue as #447.

/tmp/scoverage_snippet16088674966675160284.scala:3: error: Found a dangling UndefinedParam at Position(file:/tmp/scoverage_snippet16088674966675160284.scala,3,46). This is likely due to a bad interaction between a macro or a compiler plugin and the Scala.js compiler plugin. If you hit this, please let us know.
object JSONHelper {

@armanbilge
Copy link
Contributor Author

Politely pinging @exoego who PRed the original fix in #281. Now that I have the test working, if you are able to help at all would be much appreciated! Thanks :)

@armanbilge
Copy link
Contributor Author

So far it seems like the problem is detecting Scala.js itself.

private val isScalaJsEnabled: Boolean = {
try {
rootMirror.getClassIfDefined("scala.scalajs.js.Any") != NoSymbol
} catch {
case _: Throwable => false
}
}

If I change that to return true in the catch, then the test passes (with a minor adjustment to number of measured statements).

I'm hopeless to get it to print out the error 😕

@armanbilge
Copy link
Contributor Author

Ok, got a stack trace that's thrown when calling rootMirror. Any ideas?

java.lang.NullPointerException
        at scala.reflect.internal.SymbolTable.phase_$eq(SymbolTable.scala:243)
        at scala.reflect.internal.SymbolTable.pushPhase(SymbolTable.scala:247)
        at scala.reflect.internal.SymbolTable.exitingPhase(SymbolTable.scala:290)
        at scala.reflect.internal.Symbols$TypeHistory.phaseString(Symbols.scala:3850)
        at scala.reflect.internal.Symbols$TypeHistory.$anonfun$toString$1(Symbols.scala:3852)
        at scala.collection.Iterator$$anon$9.next(Iterator.scala:577)
        at scala.collection.IterableOnceOps.addString(IterableOnce.scala:1184)
        at scala.collection.IterableOnceOps.addString$(IterableOnce.scala:1179)
        at scala.collection.AbstractIterator.addString(Iterator.scala:1293)
        at scala.collection.IterableOnceOps.mkString(IterableOnce.scala:1129)
        at scala.collection.IterableOnceOps.mkString$(IterableOnce.scala:1127)
        at scala.collection.AbstractIterator.mkString(Iterator.scala:1293)
        at scala.reflect.internal.Symbols$TypeHistory.toString(Symbols.scala:3852)
        at java.base/java.lang.String.valueOf(String.java:2951)
        at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:171)
        at scala.reflect.internal.Symbols$TypeHistory.<init>(Symbols.scala:3831)
        at scala.reflect.internal.Symbols$TypeHistory$.apply(Symbols.scala:3829)
        at scala.reflect.internal.Symbols$Symbol.info_$eq(Symbols.scala:1586)
        at scala.reflect.internal.Symbols$TypeSymbol.info_$eq(Symbols.scala:3256)
        at scala.reflect.internal.Symbols$Symbol.setInfo(Symbols.scala:1592)
        at scala.reflect.internal.Mirrors$Roots$RootClass.<init>(Mirrors.scala:313)
        at scala.reflect.internal.Mirrors$Roots.RootClass$lzycompute(Mirrors.scala:327)
        at scala.reflect.internal.Mirrors$Roots.RootClass(Mirrors.scala:327)
        at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.<init>(Mirrors.scala:336)
        at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass$lzycompute(Mirrors.scala:342)
        at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:342)
        at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:282)
        at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:256)
        at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:75)
        at scala.tools.nsc.Global.rootMirror(Global.scala:73)
        at scoverage.ScoverageInstrumentationComponent.liftedTree1$1(ScoveragePlugin.scala:104)

@armanbilge
Copy link
Contributor Author

Aha, I think making it lazy does the trick.

@armanbilge armanbilge changed the title Re-enable PluginCoverageScalaJsTest Re-enable PluginCoverageScalaJsTest, fix dangling UndefinedParam bug May 31, 2022
@armanbilge armanbilge marked this pull request as ready for review May 31, 2022 10:10
@armanbilge
Copy link
Contributor Author

I can confirm the fix (as released in 2.0.0-M7+1-9cfca69b-SNAPSHOT) works in downstreams 👍

Copy link
Member

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

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

This looks good @armanbilge. Just a quick question on the buildInfo module though.

@@ -179,6 +181,16 @@ lazy val reporter =
)
.dependsOn(domain, serializer)

lazy val buildInfo =
Copy link
Member

Choose a reason for hiding this comment

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

How come we have a separate build target for buildInfo instead of just including the buildInfo stuff inside of the plugin module and enabling the BuildInfoPlugin there?

Copy link
Contributor Author

@armanbilge armanbilge Jun 3, 2022

Choose a reason for hiding this comment

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

Aha, yes I suppose we could. I did this because the BuildInfo was only needed in the Test scope and there's currently no way to configure that (see sbt/sbt-buildinfo#186). But I guess here if we "leak" the BuildInfo as part of the shipped plugin, it's probably not a big deal?

Copy link
Member

Choose a reason for hiding this comment

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

was only needed in the Test scope

Yea, that's sort of what I expected. No worries. Let's leave it as is.

Comment on lines -149 to +151
.dependsOn(runtimeJVM % Test)
// we need both runtimes compiled prior to running tests
.dependsOn(runtimeJVM % Test, runtimeJS % Test)
Copy link
Member

Choose a reason for hiding this comment

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

Ah this make sense. 👍🏼 good catch.

Copy link
Member

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

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

Alrighty, LGTM. Thanks @armanbilge!

@ckipp01 ckipp01 merged commit 7eba8e1 into scoverage:main Jun 3, 2022
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.

Found a dangling UndefinedParam on Scala.js
2 participants