Skip to content

Scoverage: lifted stable argument gets a new capture identity in Iterator.iterate #26784

Description

@anatoliykmetyuk

Compiler version

3.10.0-RC1-bin-SNAPSHOT - on latest main as of 6 August 2026, commit 266b5b3afe.

Minimized code

import language.experimental.captureChecking

trait Repro[A]:
  def toIterable: Iterable[A]^{this}

  def iterate(f: Iterable[A]^{this} => Iterable[A]^{this}) =
    Iterator.iterate(toIterable)(f)

Command

sbt -error -no-colors "scala3-bootstrapped/scalac -color:never -Ycheck:instrumentCoverage -coverage-out target/issue-coverage -sourceroot . -d target/issue-out Repro.scala"

Output

checking Repro.scala after phase instrumentCoverage
-- [E007] Type Mismatch Error: Repro.scala:7:33 -------------------------------
7 |    Iterator.iterate(toIterable)(f)
  |                                 ^
  |Found:    Iterable[A]^{Repro.this} ->{f, start$1} Iterable[A]^{Repro.this}
  |Required: Iterable[A^'s1]^{start$1} => Iterable[A^'s1]^{start$1}
  |
  |Note that capability `Repro.this` cannot flow into capture set {start$1}.
  |
  |where:    => refers to a root capability created in method iterate when checking argument to parameter f of method iterate²
1 error found
[error] nonzero exit code returned from runner: 1
[error] (scala3-compiler-bootstrapped / Compile / runMain) nonzero exit code returned from runner: 1

Expectation

Compilation succeeds with coverage instrumentation and YCheck.

Notes

Is a blocker for scoverage to work with stdlib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coverageCode coverage, see https://dotty.epfl.ch/docs/internals/coverage.htmlarea:experimental:ccCapture checking relateditype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions