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

Code coverage crashes at runtime #15078

Closed
MasseGuillaume opened this issue Apr 30, 2022 · 6 comments · Fixed by #15530
Closed

Code coverage crashes at runtime #15078

MasseGuillaume opened this issue Apr 30, 2022 · 6 comments · Fixed by #15530
Assignees
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html itype:bug itype:crash
Milestone

Comments

@MasseGuillaume
Copy link
Contributor

I was testing the new coverage support for scala3 with:

The latest version of sbt-scoverage
https://github.com/scoverage/sbt-scoverage/tree/V2

with https://github.com/scoverage/sbt-scoverage/blob/V2/src/main/scala/scoverage/ScoverageSbtPlugin.scala#L162 set to 3.2.0-RC1-bin-SNAPSHOT

This call crashes with the instrumented code:

https://github.com/MasseGuillaume/porc-epic/blob/main/src/test/scala/porcEpic/unit/VisualizationTest.scala#L53

https://github.com/MasseGuillaume/porc-epic/blob/07157829817afd03d286f056f3c0dda3fd5e6eca/src/main/scala/porcEpic/Visualization.scala#L59-L80

Compiler version

latest (main branch)

Minimized code

import java.nio.file._
import java.io.File

extension (v: Int) {
  def save(): File = {
    Files.createTempDirectory("porc-epic").toFile
  }
}

1.save()

Output (click arrow to expand)

java.lang.ClassCastException: class scala.collection.immutable.ArraySeq$ofRef cannot be cast to class [Ljava.nio.file.attribute.FileAttribute; (scala.collection.immutable.ArraySeq$ofRef is in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @53bcaacb; [Ljava.nio.file.attribute.FileAttribute; is in module java.base of loader 'bootstrap') at porcEpic.Visualization$package$.save(Visualization.scala:61) at porcEpic.unit.VisualizationTest.$init$$$anonfun$2(VisualizationTest.scala:91)
@MasseGuillaume MasseGuillaume added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 30, 2022
@MasseGuillaume MasseGuillaume changed the title Code coverage crashes the compiler Code coverage crashes at runtime Apr 30, 2022
@smarter
Copy link
Member

smarter commented Apr 30, 2022

Can you take a look @TheElectronWill ?

@TheElectronWill
Copy link
Contributor

I'll take a look. Thanks for reporting!

@smarter
Copy link
Member

smarter commented Apr 30, 2022

This issue has a really high concentration of Guillaumes 😅

@som-snytt
Copy link
Contributor

Will power!

@MasseGuillaume
Copy link
Contributor Author

This issue has a really high concentration of Guillaumes sweat_smile

Guillaume³ taking over the world.

@TheElectronWill TheElectronWill self-assigned this May 1, 2022
@smarter smarter added area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 2, 2022
@TheElectronWill
Copy link
Contributor

TheElectronWill commented May 16, 2022

It seems that the types generated by the lifter are not treated correctly by the following phases, in the case of varargs with type arguments.
Produced code, with coverage enabled:

extension (v: Int) def save(): java.io.File = 
      {
        scala.runtime.coverage.Invoker.invoked(2, "target/o")
        {
          {
            scala.runtime.coverage.Invoker.invoked(1, "target/o")
            {
              val $1$: String = "porc-epic"
              val $2$: java.nio.file.attribute.FileAttribute[?]* = 
                ([ : java.nio.file.attribute.FileAttribute[?]]*)
              {
                scala.runtime.coverage.Invoker.invoked(0, "target/o")
                java.nio.file.Files.createTempDirectory($1$, $2$)
              }
            }.toFile()
          }
        }
      }

-Ycheck:all catches the problem at refchecks:

*** error while checking target/bug.scala after phase refchecks ***
exception occurred while compiling target/bug.scala
java.lang.AssertionError: assertion failed: Found:    ($2$ : java.nio.file.attribute.FileAttribute[?]*)
Required: Array[? <: java.nio.file.attribute.FileAttribute[?]]
found: ??
expected: ??

Note that the parser produces

java.nio.file.Files.createTempDirectory("porc-epic", 
          [ : java.nio.file.attribute.FileAttribute[?]]*
        )

which works OK. But using such a type for a variable doesn't seem to be supported. Is it expected?

TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jun 25, 2022
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 2, 2022
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 2, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
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 itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants