Skip to content

Intersection, match types and tuples don't work together #12800

Closed
@Katrix

Description

@Katrix

Compiler version 3.0.0

Seems the compiler doesn't like it when intersection, match types and tuples are used together. Yes, opaque types are a better match here, but need this for Shapeless, and don't want to break the API here.

Minimized code

Use only one definition of WrapUpper and Wrap in the below code. The one relying on tuples does not work, while the one using a sealed trait does

type FieldType2[K, +V] = V with KeyTag2[K, V]
trait KeyTag2[K, +V] extends Any

//summon[TupleToHList[Tuple1[FieldType2["i", Int]]] =:= (FieldType2["i", Int] :: HNil)]

sealed trait ABox
trait Box[A] extends ABox

//Works
//type WrapUpper = ABox
//type Wrap[A] = Box[A]

//Doesn't work
type WrapUpper = Tuple
type Wrap[A] = Tuple1[A]

type Extract[A <: WrapUpper] = A match {
  case Wrap[h] => h
}

type ExtractWrap1[A, Wrap[_]] = Wrap[A] match {
  case Wrap[h] => h
}

type ExtractWrap2[A] = Extract[Wrap[A]]

summon[Extract[Wrap[Int]] =:= Int] //Works
summon[Extract[Wrap[FieldType2["foo", Int]]] =:= FieldType2["foo", Int]] //Does not reduce
summon[ExtractWrap1[FieldType2["foo", Int], Wrap] =:= FieldType2["foo", Int]] //Works
summon[ExtractWrap2[FieldType2["foo", Int]] =:= FieldType2["foo", Int]] //Works

Output

[error] -- Error: D:\DevProjects\Incubating\shapeless2-port-start\src\main\scala\shapeless\testing.scala:61:74
[error] 61 |  summon[Extract[Wrap[FieldType2["foo", Int]]] =:= FieldType2["foo", Int]] //Does not reduce
[error]    |                                                                          ^
[error]    |           Cannot prove that shapeless.TypeBug.Extract[
[error]    |             Tuple1[shapeless.TypeBug.FieldType2[("foo" : String), Int]]
[error]    |           ] =:= shapeless.TypeBug.FieldType2[("foo" : String), Int].

Expectation

It should compile. Putting the Extract and Wrap types closer together does work fine, which works counter to how I would expect them to work. Either none, or all.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions