Skip to content

Parameter untupling does not accommodate varargs #17779

@som-snytt

Description

@som-snytt

Compiler version

3.1.0

Minimized code

scala> val xs = List(1->10,2->20)
val xs: List[(Int, Int)] = List((1,10), (2,20))

scala> def f(n: Int*) = n.sum
def f(n: Int*): Int

scala> xs.map(f)
-- Error:
1 |xs.map(f)
  |       ^
  |       Found:    Seq[Int] => Int
  |       Required: ((Int, Int)) => Int

scala> def g(i: Int, j: Int) = i+j
def g(i: Int, j: Int): Int

scala> xs.map(g)
val res0: List[Int] = List(11, 22)

Output

-- Error:

Expectation

Adapt the tuple to my repeated parameter.

Implies #14367

A snag is the spec language that "n > 1". The impedance is def f[A](as: A*) because A can be the arbitrary tuple. But that is fine, it just says the adaptation is not needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions