Skip to content

Regression in foldables-io/skunk-tables for match types: with error "selector is uninhabited" but selector is actually inhabited #21295

Closed
@WojciechMazur

Description

@WojciechMazur

Compiler version

Last good release: 3.6.0-RC1-bin-20240719-af933c4-NIGHTLY
First bad release: 3.6.0-RC1-bin-20240723-46ff151-NIGHTLY
Bisect points to b7846c4

Minimized code

import scala.compiletime.constValueTuple

trait IsColumn[A]

final case class TypedColumn[N <: Singleton, A, T, C <: Tuple](name: N, primitive: IsColumn[A])
object TypedColumn:
  enum Constraint:
    case Default
    case Nullable

  final class Insert[N <: Singleton, A, C <: Tuple, In](name: N, isColumn: IsColumn[A])
  final case class Op[A](a: A)

type IfIn[T <: Tuple, A, True, False] <: True | False = T match
  case EmptyTuple => False
  case A *: t     => True
  case ? *: t     => IfIn[t, A, True, False]

type IfInM[T <: Tuple, A <: Tuple, True, False] <: True | False =
  A match
    case EmptyTuple => False
    case a *: tail  => IfIn[T, a, True, IfInM[T, tail, True, False]]

type NonRequiredConstraints =
  (TypedColumn.Constraint.Nullable.type, TypedColumn.Constraint.Default.type)

type Required[C <: NonEmptyTuple] <: Tuple =
  C match
    case TypedColumn.Insert[n, ?, c, ?] *: t =>
      RequiredGo[t, IfInM[c, NonRequiredConstraints, EmptyTuple, n *: EmptyTuple]]
type RequiredGo[C <: Tuple, A <: Tuple] <: Tuple =
  C match
    case EmptyTuple => A
    case TypedColumn.Insert[n, ?, c, ?] *: t =>
      RequiredGo[t, IfInM[c, NonRequiredConstraints, A, scala.Tuple.Append[A, n]]]

@main def Test = {
    type Columns = (TypedColumn.Insert["one", Boolean, EmptyTuple, Nothing],
                  TypedColumn.Insert["two", Int, EmptyTuple, Nothing],
                  TypedColumn.Insert["three", String, EmptyTuple, Nothing])

    assert(constValueTuple[Required[Columns]] == ("one", "two", "three"))
}

Output

[error] ./src/main/scala/usage.scala:42:12
[error] Values of types Required[Columns] and (String, String, String) cannot be compared with == or !=
[error] 
[error] Note: a match type could not be fully reduced:
[error] 
[error]   trying to reduce  Required[Columns]
[error]   failed since selector Columns
[error]   is uninhabited (there are no values of that type).
[error]     assert(constValueTuple[Required[Columns]] == ("one", "two", "three"))

Expectation

Should compile (probably)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions