Skip to content

SAM doesn't work with polymorphic functions #6904

Open
@guyde2011

Description

@guyde2011

minimized code

trait List2Option{
  def apply[A](list: List[A]): Option[A]
}

val l2o: List2Option = [A] => (lst: List[A]) => lst.headOption

This code does not compile, with the error message
Found: Object with PolyFunction {...}
Required: List2Option

expectation

Would expect the compiler to accept it as a SAM implementation of List2Option, the same way it does with other irregular function types (as it does with dependant functions for example).

I will add that the following (quite unsuprisingly) does work, but this way forces you to use a pair of brackets on the apply method in List2Option

trait List2Option{
  def apply(): [A] => List[A] => Option[A]
}

val l2o: List2Option = () => [A] => (lst: List[A]) => lst.headOption

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