Skip to content

More careful ClassTag instantiation #23659

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

Merged
merged 4 commits into from
Aug 6, 2025
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 4, 2025

We now use a blend of the new scheme and a backwards compatible special case if type variables as ClassTag arguments are constrained by further type variables.

Fixes #23611

We now use a blend of the new scheme and backwards compatible special case if type variables
as ClassTag arguments are constrained by further type variables.

Fixes scala#23611
@WojciechMazur
Copy link
Contributor

WojciechMazur commented Aug 5, 2025

I've tried it on community build, but the zio project is still failing - I've figured out that the reproducer was missing an important part - the CanFail[E] implicit evidence in refineToOrDie extension method. With this additional requirement it still fails:

[error] ./example.scala:52:7
[error] Found:    ZStream[Any, Throwable, java.io.File]
[error] Required: ZStream[Any, java.io.IOException, java.io.File]
Error compiling project (Scala 3.8.0-RC1-bin-20250805-2b604c5, JVM (21))

Below there's a full reproducer:

import java.io.{File, IOException}
import java.net.URI
import java.nio.file.{Path, Paths}
import scala.reflect.ClassTag

trait FileConnectors { 
  def listPath(path: => Path): ZStream[Any, IOException, Path]

  final def listFile(file: => File): ZStream[Any, IOException, File] =
    for {
      path <- null.asInstanceOf[ZStream[Any, IOException, Path]]
      r    <- listPath(path).mapZIO(a => ZIO.attempt(a.toFile).refineToOrDie)
    } yield r
}

sealed abstract class CanFail[-E]
object CanFail:
  given [E]: CanFail[E] = ???
  
sealed trait ZIO[-R, +E, +A]
extension [R, E <: Throwable, A](self: ZIO[R, E, A])
  def refineToOrDie[E1 <: E: ClassTag](using CanFail[E]): ZIO[R, E1, A] = ???

object ZIO:
  def attempt[A](code: => A): ZIO[Any, Throwable, A] = ???
  
sealed trait ZStream[-R, +E, +A]:
  def map[B](f: A => B): ZStream[R, E, B] = ???
  def flatMap[R1 <: R, E1 >: E, B](f: A => ZStream[R1, E1, B]): ZStream[R1, E1, B]
  def mapZIO[R1 <: R, E1 >: E, A1](f: A => ZIO[R1, E1, A1]): ZStream[R1, E1, A1]

@odersky
Copy link
Contributor Author

odersky commented Aug 6, 2025

The latest minimization also compiles now.

@odersky odersky assigned WojciechMazur and unassigned odersky Aug 6, 2025
Copy link
Contributor

@WojciechMazur WojciechMazur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, fixes the zio-archive/zio-connect build, but does not resolve erikerlandson/coulomb issues yet

@WojciechMazur WojciechMazur merged commit cfaa5d3 into scala:main Aug 6, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in typer for zio-archive/zio-connect
2 participants