Skip to content
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

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

Closed
rnd4222 opened this issue Aug 28, 2020 · 1 comment
Closed

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

rnd4222 opened this issue Aug 28, 2020 · 1 comment

Comments

@rnd4222
Copy link

rnd4222 commented Aug 28, 2020

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.

@rnd4222
Copy link
Author

rnd4222 commented Aug 28, 2020

Same error with kind-polymorphic types:

import scala.compiletime.S

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

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

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

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

@OlivierBlanvillain OlivierBlanvillain removed their assignment Aug 4, 2021
@OlivierBlanvillain OlivierBlanvillain self-assigned this Aug 4, 2021
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Aug 6, 2021
@odersky odersky closed this as completed in 6190702 Aug 6, 2021
odersky added a commit that referenced this issue Aug 6, 2021
Fix #9675: Type _ in MT patterns with correct kind
tanishiking pushed a commit to tanishiking/scala3 that referenced this issue Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants