Skip to content

Regression in jcouyang/dhall-generic for implicit search  #20298

Closed as not planned
@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failures in jcouyang/dhall-generic - build logs

The compiler fails to search for implicit instances defined in companion of the typeclass. It requires explicit import at the place of usage

Compiler version

Last good release: 3.5.0-RC1-bin-20240406-521ce95-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240408-1e8a653-NIGHTLY

The compilation errors when building compiler prevented gathering the exact commit that coused regression it can be any of:
d2a6392
1dc5b99
321d0d2
1e8a653

The project-wise bisect nominated 90c3fbd as the cause of the regression

Minimized code

Needs to be defined as 2 compilation units
I was able to reproducer Decoder[Empty] in single file, but the other cases required definitions and usage to be split in previous Scala versions.

// 1_defns.scala
import scala.compiletime.*
import scala.deriving.*

sealed trait Decoder[T]
object Decoder:
  inline given summonEmptyTuple[H]: Tuple.Map[EmptyTuple.type, Decoder] = EmptyTuple
  inline given summonTuple[H, T <: Tuple](using
      hd: Decoder[H],
      td: Tuple.Map[T, Decoder]
  ): Tuple.Map[H *: T, Decoder] = hd *: td
  inline given derived[T](using
      m: Mirror.Of[T],
      d: Tuple.Map[m.MirroredElemTypes, Decoder]
  ): Decoder[T] = ???
  given Decoder[Double] = ???
// 2_usage.scala
case class Empty()
object Empty {
  val fails = Decoder.derived[Empty]
}

enum Shape:
  case Rectangle(width: Double, height: Double)
  case Circle(radius: Double)

object Shape:
  val fails1 = Decoder.derived[Rectangle]
  val fails2 = Decoder.derived[Shape]

Output

-- [E172] Type Error: /Users/wmazur/projects/sandbox/repro.test.scala:4:39 -----
4 |  val instance = Decoder.derived[Empty]
  |                                       ^
  |No given instance of type Tuple.Map[m.MirroredElemTypes, Decoder] was found for parameter d of given instance derived in object Decoder
  |
  |Note: a match type could not be fully reduced:
  |
  |  trying to reduce  Tuple.Map[m.MirroredElemTypes, Decoder]
  |  failed since selector m.MirroredElemTypes
  |  does not match  case EmptyTuple => EmptyTuple
  |  and cannot be shown to be disjoint from it either.
  |  Therefore, reduction cannot advance to the remaining case
  |
  |    case h *: t => Decoder[h] *: Tuple.Map[t, Decoder]
-- [E172] Type Error: /Users/wmazur/projects/sandbox/repro.test.scala:12:38 ----
12 |  val rec = Decoder.derived[Rectangle]
   |                                      ^
   |No given instance of type Tuple.Map[m.MirroredElemTypes, Decoder] was found for parameter d of given instance derived in object Decoder.
   |I found:
   |
   |    Decoder.summonTuple[Double, Double *: EmptyTuple.type](
   |      Decoder.given_Decoder_Double,
   |      Decoder.summonTuple[Double, EmptyTuple.type](Decoder.given_Decoder_Double,
   |        /* missing */summon[Tuple.Map[EmptyTuple.type, Decoder]])
   |    )
   |
   |But no implicit values were found that match type Tuple.Map[EmptyTuple.type, Decoder].
   |
   |Note: a match type could not be fully reduced:
   |
   |  trying to reduce  Tuple.Map[m.MirroredElemTypes, Decoder]
   |  failed since selector m.MirroredElemTypes
   |  does not match  case EmptyTuple => EmptyTuple
   |  and cannot be shown to be disjoint from it either.
   |  Therefore, reduction cannot advance to the remaining case
   |
   |    case h *: t => Decoder[h] *: Tuple.Map[t, Decoder]
3 errors found

Expectation

Should compile

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions