Skip to content

Type checking error when mixing inline defs, match types, and applied type constructors #8321

Closed
@mpilquist

Description

@mpilquist

minimized code

scala> inline def concat[A <: Tuple, B <: Tuple](a: Option[A], b: Option[B]): Option[Tuple.Concat[A, B]] =
     |   a.zip(b).map(_ ++ _)
def concat
  [A <: Tuple, B <: Tuple]
    (a: Option[A], b: Option[B]): Option[Tuple.Concat[A, B]]

scala> concat(Some(1, 2), Some(3, 4)) // This should work
1 |concat(Some(1, 2), Some(3, 4))
  |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |Found:    Int *: Int *: scala.Tuple.Concat[Unit, (Int, Int)]
  |Required: Int *: scala.Tuple.Concat[Int *: Unit, Singleton & (Int, Int)]
  | This location contains code that was inlined from rs$line$12:2

scala> inline def concat2[A <: Tuple, B <: Tuple](a: Option[A], b: Option[B]): Option[Tuple.Concat[A, B]] =
     |   a.zip(b).map((a, b) => (a ++ b).asInstanceOf[Tuple.Concat[A, B]])
def concat2
  [A <: Tuple, B <: Tuple]
    (a: Option[A], b: Option[B]): Option[Tuple.Concat[A, B]]

scala> concat2(Some(1, 2), Some(3, 4))
val res5: Option[(Int, Int, Int, Int)] = Some((1,2,3,4))

scala> inline def concat3[A <: Tuple, B <: Tuple](a: A, b: B): Tuple.Concat[A, B] =
     |   a ++ b
def concat3[A <: Tuple, B <: Tuple](a: A, b: B): Tuple.Concat[A, B]

scala> concat3((1, 2), (3, 4))
val res7: (Int, Int, Int, Int) = (1,2,3,4)

Both concat2 and concat3 work. Removing inline from concat also works.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions