scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Coverage generated for inlined Predef function

Open Martomate opened this issue 1 year ago • 2 comments

Compiler version

3.2.0-RC3

Minimized code

@main def a(b: Int): Unit = {
  assert(b == 1)
}

The assert function is part of the Scala 3 library at scala.runtime.stdLibPatches.Predef and has this definition:

transparent inline def assert(inline assertion: Boolean): Unit =
  if !assertion then scala.runtime.Scala3RunTime.assertFailed()

Output

scoverage.coverage contains entries for library/src/scala/runtime/stdLibPatches/Predef.scala.

As a result sbt coverageReport fails with the following error:

No source root found for '/Users/martin/git/myproject/library/src/scala/runtime/stdLibPatches/Predef.scala' (source roots: '/Users/martin/git/myproject/src/main/scala/')

Expectation

No coverage entries should be generated for the Predef file, just like all other files in the Scala library.

This issue seems to be related to #15490.

Martomate avatar Aug 01 '22 09:08 Martomate

I think it would be good to report calls to the standard library (and to any library) as covered, even if they're not in the project's codebase. It would be better for sbt-coverage not to fail. The issue may be on the sbt-coverage side.

TheElectronWill avatar Aug 01 '22 11:08 TheElectronWill

Most probably not on sbt plugin side, but in the core module. But previously they stated that will not fix it at least for Macro libraries https://github.com/scoverage/scalac-scoverage-plugin/issues/474

This case is not purely macro, but an inline. Though it is could be questioned if inlined parts should be reported with external source reference if this is an actual code "placed" elsewhere. Similarly with macro code.

An option to hide this behind some configuration key would be appreciated I believe as in some cases people might don't want the coverage info from sources they don't own.

arixmkii avatar Aug 01 '22 12:08 arixmkii