Skip to content

Tuple semigroupal syntax widens constant type in Scala 3 #4770

@mrdziuban

Description

@mrdziuban

Given that this only happens in Scala 3 I'm not sure if anything can be done in cats to fix it, but figured I'd start by reporting it here.

When using the tuple semigroupal syntax, e.g. (...).tupled or (...).mapN, constant types in the tuple are widened to their underlying type. For example:

import cats.syntax.apply._

val e1: Either[Unit, "a"] = Right("a")
val e2: Either[Unit, Int] = Right(1)

(e1, e2).tupled
// type is         `Either[Unit, (String, Int)]`
// desired type is `Either[Unit, ("a", Int)]`

Annotating the result with the desired type does work, but IMO it adds unwanted noise

// both of these compile
val x: Either[Unit, ("a", Int)] = (e1, e2).tupled
(e1, e2).tupled: Either[Unit, ("a", Int)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions