Skip to content

Unary function with argument of type Unit is not type-safe #12495

Closed
scala/scala
#10150
@otto-dev

Description

@otto-dev

reproduction steps

using Scala 2.13.6,

scala> val f = (a: Unit) => println(s"Received $a")
val f: Unit => Unit = $Lambda$2279/411876574@4ee6291f

scala> f("foo", "bar", "baz")
Received ()

problem

The compiler should not allow the arguments ("foo", "bar", "baz") to be passed to a function that expects one Unit argument. This is particularly problematic for higher-order functions that may return a unary A => Unit function, with A being Unit in situations where the first function argument is irrelevant.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions