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

No source root found for .../modules/core/shared/src/main/scala-3/io/circe/Derivation.scala #444

Closed
nikololiahim opened this issue Jul 4, 2022 · 19 comments
Labels

Comments

@nikololiahim
Copy link

nikololiahim commented Jul 4, 2022

I don't know if this affects only circe or any code that uses the derives keyword.

To reproduce:

  1. Clone this gist.
  2. (idk if this affects anything) move User.scala to src/main/scala folder and UserTest.scala to src/test/scala folder.
  3. Run sbt clean coverage test coverageReport

Problem

The command fails with:

[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/')
@ckipp01
Copy link
Member

ckipp01 commented Jul 4, 2022

Thanks for the report @nikololiahim. Can you verify if the behavior is the same or different if you use 2.13.8. If it's not then it would be a problem in the actual Scala 3 compiler and we can move this issue over there.

@nikololiahim
Copy link
Author

@ckipp01 Just tried with 2.13.8, seems to work correctly. I had to rewrite the code a bit:
User.scala

import io.circe._
import io.circe.generic.semiauto._

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

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

And also add

"io.circe" %% "circe-generic-extras" % "0.14.2",

to build.sbt.

Seems like the problem is indeed tied to the derives keyword.

@ckipp01
Copy link
Member

ckipp01 commented Jul 4, 2022

Gotcha, since this works for 2.13, are you then able to create an issue for this over at https://github.com/lampepfl/dotty/issues since I believe it will actually need to be fixed over there.

@nikololiahim
Copy link
Author

@ckipp01 Should I copy it as is or should I reword it somehow?

@ckipp01
Copy link
Member

ckipp01 commented Jul 4, 2022

You can just copy and just ensure that you have a minimal reproduction.

@nikololiahim
Copy link
Author

seems like it was already reported: scala/scala3#15490

@ckipp01
Copy link
Member

ckipp01 commented Jul 4, 2022

seems like it was already reported: scala/scala3#15490

Ah, perfect. I totally missed that.

@rochala
Copy link

rochala commented Jul 4, 2022

@ckipp01 I checked this issue on dotty side and the generation looks to be working as intended. I closed the issue as scoverage.coverage contained derived methods and whole test project passed and compiled under -coverage-out:. flag. The problem is also not connected to this issue scala/scala3#15490 as it is about coverage data generated from macros which led to misleading data.

@nikololiahim
Copy link
Author

The issue is still present with Scala 3.2.1-RC1.

@ruippeixotog
Copy link

This issue seems to be preventing PureConfig from enabling coverage on Scala 3 (pureconfig/pureconfig#1387).

@z4f1r0v
Copy link

z4f1r0v commented Oct 24, 2022

Same thing with Scala 3.2.0 and circeVersion 0.15.0-M1

@ckipp01
Copy link
Member

ckipp01 commented Oct 24, 2022

Note that this is probably the same issue as in #458 and I believe should be fixed by the work in scala/scala3#16235.

@TheElectronWill
Copy link

IMO, fixing the coverage instrumentation is good but the report writer of scoverage should be able to ignore missing sources 🤔 Design for failure :)

@ckipp01
Copy link
Member

ckipp01 commented Oct 24, 2022

IMO, fixing the coverage instrumentation is good but the report writer of scoverage should be able to ignore missing sources

But then how else would we know the instrumentation is broken! Jokes aside, it's probably a good idea to loudly warn the user in this situation but gracefully continue. As you said it'd require some small changes in https://github.com/scoverage/scalac-scoverage-plugin, which I'd be happy to review.

@z4f1r0v
Copy link

z4f1r0v commented Oct 31, 2022

Apologies for being a pest but what is the state now? It looks like scala/scala3#16235 is merged (thank you @TheElectronWill). I see that dotty is at 3.2.1-RC4. Will that changset make it in 3.2.1?

If that is the case, from what I get from this thread, a subsequent change needs to be made to https://github.com/scoverage/scalac-scoverage-plugin? Is that what is supposed to happen or am I misunderstanding?

@ckipp01
Copy link
Member

ckipp01 commented Oct 31, 2022

Will that changset make it in 3.2.1?

3.2.1 is actually released already, just not announced as the other parts of the ecosystem need to catch up. https://github.com/lampepfl/dotty/releases/tag/untagged-6fa1a15db952f2cb4a28

If that is the case, from what I get from this thread, a subsequent change needs to be made to https://github.com/scoverage/scalac-scoverage-plugin? Is that what is supposed to happen or am I misunderstanding?

Nope, this will just be fixed when the coverage output from the compiler is fixed. There are some changes we can make to maybe hand this type of situation a bit better though, and I'm open to review those changes.

@z4f1r0v
Copy link

z4f1r0v commented Nov 20, 2022

Scala 3.2.2-RC1 solved this for me.

@ckipp01
Copy link
Member

ckipp01 commented Nov 21, 2022

Scala 3.2.2-RC1 solved this for me.

Thanks for confirming @z4f1r0v. I'll go ahead and close this then. If anyone else is hitting on this and 3.2.2-RC1 doesn't fix it for them, please report back.

@ckipp01 ckipp01 closed this as completed Nov 21, 2022
@godenji
Copy link

godenji commented Jun 19, 2023

Getting the "No source root found for ..." error on scala-3.3.1-RC1, although in my case it's not related to the derives keyword.

Could be a cross project issue? The listed source roots are correct, but where scoverage thinks the missing source file is is not correct -- it's looking in the top-level project (where sbt console session is initiated) instead of correct source root directory).

No idea why this is happening, but it makes scoverage in a multi-project build unusable at the moment.

EDIT

If I run tests/coverageReport from individual subprojects then everything works as expected. Not ideal, but it will have to do for now. I'll see if I can come up with a minimal repro and file a separate issue -- I suspect cross project + ProjectRefs are not supported yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants