Tuple semigroupal syntax widens constant type in Scala 3
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
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)]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported widening with the Scala 3 examples, then start at the cats syntax for tupled and mapN. Trace how the semigroupal syntax derives its result type and add a regression test if the behavior can be changed; done means preserving the singleton "a" type without a result annotation, or documenting the confirmed Scala 3 limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100