'How to merge two values into an intersection type in Scala 3

Suppose we have the following code:

object Main extends App {

  sealed trait A
  final case class A1(a1: Int) extends A
  final case class A2(a2: Int) extends A

  final case class B(b: Int)

  val a: A = A1(1)
  val b: B = B(2)
  val c: (A & B) = ???
}

Is it possible to create a value of type A & B from values a and b?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source