question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intersection, match types and tuples don't work together

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Katrixcommented, Aug 9, 2021

It does yes, and what’s currently used

0reactions
joroKr21commented, Aug 9, 2021

Does opaque type FieldType[K, +V] <: V = V work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regression: Intersection of array and tuple not assignable to ...
The issue here is that we lack the ability to relate a tuple type with a rest element on the target side to...
Read more >
Fastest algorithm to get all the tuple groups that has the same ...
Fastest algorithm to get all the tuple groups that has the same N intersections from a list of tuples without duplicates · Every...
Read more >
Handbook - Unions and Intersection Types - TypeScript
Intersection types are closely related to union types, but they are used very differently. An intersection type combines multiple types into one. This...
Read more >
Python | Intersection in Tuple Records Data - GeeksforGeeks
Sometimes, while working with data, we may have a problem in which we require to find the matching records between two lists that...
Read more >
Relational Algebra
R1 n R2 (intersection) is the relation containing all tuples that appear in both R1 and R2. R1 - R2 (set difference) is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found