Skip to content

Overloading doesn't work with given args as first param list and functions as args #7793

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

minimized code

trait Foo
  def g(f: Int => Int): Int = 1
  def g(given String)(f: Int => String): String = "2"

@main def Test =
  val m: Foo = ???
  given String = "foo"
  m.g(x => "2")
-- [E007] Type Mismatch Error: /Users/kmetiuk/Projects/scala3/pg/sandbox/iss71.scala:8:11
8 |  m.g(x => "2")
  |           ^^^
  |           Found:    ("2" : String)
  |           Required: Int
1 error found

Works if you define the second g as (move the given to the last arg group):

  def g(f: Int => String)(given String): String = "2"

Works also if you define gs as:

  def g(f: Int): Int = 1
  def g(given String)(f: String): String = "2"

And use as m.g("2").

Works also if you call m.g(x => 1).

expectation

The original case should resolve overloading correctly.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions