Skip to content

Can't reduce match type on a higher-kinded types #9675

@rnd4222

Description

@rnd4222

Minimized code

import scala.compiletime.S

sealed trait TList
sealed trait TNil extends TList
sealed trait ++:[H[_], T <: TList] extends TList

type IndexOf[H[_], T <: TList] <: Int = T match
  case H ++: _ => 0
  case _ ++: t => S[IndexOf[H, t]]

// compiles fine
val a = summon[ValueOf[IndexOf[List, List ++: Option ++: TNil]]].value

// causes an error
val b = summon[ValueOf[IndexOf[List, Option ++: List ++: TNil]]].value

object T extends App:
  println(a)

Output

[error] 45 |val b = summon[ValueOf[IndexOf[List, Option ++: List ++: TNil]]].value
[error]    |                                                                ^
[error]    |No singleton value available for IndexOf[List, Option ++: List ++: TNil].

Expectation

Note that if ++: is defined for a non-higher-kinded types (e.g. sealed trait ++:[H, T <: TList] extends TList) both of this cases compiles.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions