Description
Compiler version
Scala compiler version 3.6.1
Minimized code
Consider the following:
object One:
def f(): Int = 1
def f()(using Boolean): Int = 2
val x1 = f()
object Two:
given f(): Int = 1
given f()(using Boolean): Int = 2
val x2 = f()
object Three:
given f: Int = 1
given f(using Boolean): Int = 2
val x3 = f
object Four:
given Unit = ()
given f(using Unit): Int = 1
given f(using Unit, Boolean): Int = 2
val x4 = f
Output
Compiling with scala-cli
, the compiler reports ambiguous overloads in the calls to One.f
, Two.f
, and Four.f
.
Compiling with scalac
, the compiler reports ambiguous overloads in the calls to One.f
and Four.f
, and a missing given instance in Two.f
.
Expectation
While the ambiguity in One
may be expected, those in Two
and Four
aren't. Further, the errors reported by the compiler should be consistent across scala-cli
and scalac
.
I also find it puzzling that the call to Four.f
is reported ambiguous.
In Two
, note that printing the output of the typer reveals that the parameter list of the first definition of f
has been (possibly incorrectly) erased. That explains the error reported by scalac
because now calling f
with parentheses excludes the first definition.
final module class Two() extends Object() { this: Two.type =>
final given def f: Int = 1
final given def f()(using x$1: Boolean): Int = 2
val x2: <error no implicit values were found that match type Boolean> =
Two.f()(/* missing */summon[Boolean])
}
Relevant link to the specification: https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html