Skip to content

Scoverage lifting does not preserve this.type properly #26088

@anatoliykmetyuk

Description

@anatoliykmetyuk

Compiler version

3.9.0-RC1-bin-SNAPSHOT - latest main on commit 5ad714f170 as of 19th of May, 2026.

Minimized code

class C { def setA(a: Int): this.type = this }
extension (c: C) def addMode: c.type = c
val x = identity(C()).setA(???).addMode.setA(???)

Command

sbt "scala3-nonbootstrapped/scalac -Ycheck:instrumentCoverage -coverage-out . Repro.scala"

Output

Compiler output
checking Repro.scala after phase instrumentCoverage
*** error while checking Repro.scala after phase instrumentCoverage ***
Exception in thread "main" java.lang.AssertionError: assertion failed: Type Mismatch (while checking typedUnadapted):
Position: Repro.scala:3:25
Found:    ($1$ : C)
Required: (?1 : C)

tree = addMode(
  {
    val $1$: C =
      identity[C](
        {
          scala.runtime.coverage.Invoker.invoked(...)
          new C()
        }
      )
    val a$1: Nothing = ???
    scala.runtime.coverage.Invoker.invoked(...)
    $1$.setA(a$1)
  }
)

Expectation

Compilation succeeds with coverage instrumentation and -Ycheck:instrumentCoverage, matching the no-coverage compile of the same source.

Note

Detected while compiling the compiler itself with -Ycheck and coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coverageCode coverage, see https://dotty.epfl.ch/docs/internals/coverage.htmlarea:private optionsIssues tied to -Y private/internal compiler settings.itype:bugitype:crash

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions