Skip to content
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

Failure to collect coverage in the presence of the derives keyword #15580

Closed
nikololiahim opened this issue Jul 4, 2022 · 2 comments
Closed
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html stat:cannot reproduce

Comments

@nikololiahim
Copy link

nikololiahim commented Jul 4, 2022

Compiler version

3.2.0-RC1

Minimized code

I encountered this issue when using sbt-scoverage.
The full reproduction is available here, however the main file is User.scala:

import io.circe._

case class User(name: String, address: Address) derives Codec.AsObject
case class Address(country: String, city: String) derives Codec.AsObject

object User {
  def fromString(s: String): Option[User] = {
    s.split(",[ ]?") match {
      case Array(name, country, city) =>
        Some(User(name, Address(country, city)))
      case _ => None
    }
  }
}

Output

Running sbt clean coverage test coverageReport fails with an error:

[error] java.lang.RuntimeException: No source root found for '/home/nikololiahim/scala/scoverage-bug/modules/core/shared/src/main/scala-3/io/circe/Derivation.scala' (source roots: '/home/nikololiahim/scala/scoverage-bug/src/main/scala/')
[error]         at scoverage.reporter.BaseReportWriter.relativeSource(BaseReportWriter.scala:35)
[error]         at scoverage.reporter.BaseReportWriter.relativeSource(BaseReportWriter.scala:23)
[error]         at scoverage.reporter.ScoverageHtmlWriter.classRow(ScoverageHtmlWriter.scala:249)
[error]         at scoverage.reporter.ScoverageHtmlWriter.$anonfun$classesTable$2(ScoverageHtmlWriter.scala:239)
[error]         at scala.collection.immutable.List.map(List.scala:293)
[error]         at scoverage.reporter.ScoverageHtmlWriter.classesTable(ScoverageHtmlWriter.scala:239)
[error]         at scoverage.reporter.ScoverageHtmlWriter.overview(ScoverageHtmlWriter.scala:460)
[error]         at scoverage.reporter.ScoverageHtmlWriter.write(ScoverageHtmlWriter.scala:65)
[error]         at scoverage.ScoverageSbtPlugin$.writeReports(ScoverageSbtPlugin.scala:324)
[error]         at scoverage.ScoverageSbtPlugin$.$anonfun$coverageReport0$1(ScoverageSbtPlugin.scala:220)
[error]         at scoverage.ScoverageSbtPlugin$.$anonfun$coverageReport0$1$adapted(ScoverageSbtPlugin.scala:195)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]         at java.base/java.lang.Thread.run(Thread.java:833)
[error] (coverageReport) No source root found for '/home/nikololiahim/scala/scoverage-bug/modules/core/shared/src/main/scala-3/io/circe/Derivation.scala' (source roots: '/home/nikololiahim/scala/scoverage-bug/src/main/scala/')

Expectation

The report should be generated.

Notes

The error goes away when I remove the derives Codec.AsObject parts:

case class User(name: String, address: Address)
case class Address(country: String, city: String)

and the coverage is collected:
image

@nikololiahim nikololiahim added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 4, 2022
@nikololiahim
Copy link
Author

#15490 seems related, can close if it is indeed so.

@rochala
Copy link
Contributor

rochala commented Jul 4, 2022

The following issue that you submitted is not exactly the problem here as derives keyword is working as intended.

I minimized it to

import scala.deriving.*

case class Foo(x: Int) derives Show

trait Show[A]:
  def show(a: A): String

object Show:
  inline given derived[T](using m: Mirror.Of[T]): Show[T] = ???

Compilation also passes -coverage-out:. flag on project you created by running sbt test compile. This issue is thou on scoverage side and you should create issue there, as coverage generation on dotty part seems to be working correctly.

It is also not connected to #15490 as it says, that we provide coverage data on methods which are generated from macros and shouldn't be included in coverage as they affect the metrics. It was only coincidence that both mentioned circe.

@rochala rochala closed this as completed Jul 4, 2022
@rochala rochala added area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html stat:cannot reproduce and removed stat:needs triage Every issue needs to have an "area" and "itype" label itype:bug labels Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html stat:cannot reproduce
Projects
None yet
Development

No branches or pull requests

2 participants