Skip to content

Treat SAM classes's (using ...) argument lists as contextual #17670

@makkarpov

Description

@makkarpov

Currently, constructs like Foo ?=> (Bar, Baz) => Qux causes two function objects be allocated on heap. This may be especially costly on repeated invocations, as there is no way to cache second function. Usually, performance-sensitive spots are highly specialized, so someone might want to replace such declaration with a specialized trait:

trait FooFunction {
  def apply(using Foo)(a: Bar, b: Baz): Qux
}

However, currently it doesn't work as expected:

object Meow extends App {
  trait FooFunc {
    def apply(using Foo)(b: Bar): Unit
  }

  val f: FooFunc = b => println(s"bar=$b, foo=${summon[Foo]}")
  // error: expected Bar => Unit, got Unit
}

Feature request is to unify behavior of such SAM lambdas with currently present behavior of context functions.

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