Skip to content

Regression in pityka/relational3 for transparent inline with match types #24038

@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failure in pityka/relational3 - build logs

Compiler version

Last good release: 3.8.0-RC1-bin-20250915-afbb66b-NIGHTLY
First bad release: 3.8.0-RC1-bin-20250916-eb1bb73-NIGHTLY
Bisect points to b1067d9 / #23923

Minimized code

final class MBufferLong:
  final def +=(elem: Long): this.type = ???

type M[Tup <: Tuple] <: Tuple = Tup match
  case EmptyTuple => EmptyTuple
  case h *: t     => BufferOf[h] *: M[t]

type M2[T <: Tuple] <: Tuple = (T, M[T]) match
  case (h *: t, a *: b)         => BufferOf[h] *: M2[t]
  case (EmptyTuple, EmptyTuple) => EmptyTuple
  case (_, EmptyTuple)          => EmptyTuple
  case (EmptyTuple, _)          => EmptyTuple

type BufferOf[T] = T match 
  case Long              => MBufferLong

inline def append[T](t: T, buffer: BufferOf[T]): BufferOf[T] = 
  inline (t, buffer) match 
    case (x: Long, y: BufferOf[Long])     => y.+=(x)
  buffer

transparent inline def appendBuffers[T <: Tuple](t: T, buffers: M[T]): M2[T] = {
  inline (t, buffers) match 
    case abcd: ((h *: t), bh *: bt) =>
      val (hh *: tt, bh *: bt) = abcd
      val x: BufferOf[h] = append[h](hh, bh.asInstanceOf[BufferOf[h]])
      x *: appendBuffers[t](tt, bt.asInstanceOf[M[t]])
    case _: (EmptyTuple, EmptyTuple) => EmptyTuple
    case _: (_, EmptyTuple)          => EmptyTuple
    case _: (EmptyTuple, _)          => EmptyTuple
}

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/scala/community-build3/test.scala:26:37 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
26 |      val x: BufferOf[h] = append[h](hh, bh.asInstanceOf[BufferOf[h]])
   |                                     ^^
   |                                     Found:    (hh : Any)
   |                                     Required: h
   |                                     Note that implicit conversions were not tried because the result of an implicit conversion
   |                                     must be more specific than h
   |
   |                                     where:    h is a type in method appendBuffers
   |
   | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: /Users/wmazur/projects/scala/community-build3/test.scala:27:28 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
27 |      x *: appendBuffers[t](tt, bt.asInstanceOf[M[t]])
   |                            ^^
   |                            Found:    (tt : Tuple)
   |                            Required: t
   |
   |                            where:    t is a type in method appendBuffers with bounds <: Tuple
   |
   | longer explanation available when compiling with `-explain`

Expectation

Should compile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions