Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly incorrect suppression of parameter list #22380

Open
kyouko-taiga opened this issue Jan 15, 2025 · 2 comments
Open

Possibly incorrect suppression of parameter list #22380

kyouko-taiga opened this issue Jan 15, 2025 · 2 comments
Labels
area:implicits related to implicits area:runner Issues tied to the scala runner command. itype:bug

Comments

@kyouko-taiga
Copy link
Contributor

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

@kyouko-taiga kyouko-taiga added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 15, 2025
@som-snytt
Copy link
Contributor

som-snytt commented Jan 15, 2025

I see the same behavior with scala-cli, with No given instance in Two.

Sharp eyes on the missing parens in Two!

Edit: I have the revised "given instances" page open in a tab, but obviously never understood it.

The "conditions" for the given become using clauses, but it can't be empty; that is, a using clause can't be empty. In new syntax, Two is:

  given f: (x: DummyImplicit) => Int = 1
  given f: (x: Boolean) => Int = 2
  val x2 = f(using true)

which is "properly ambiguous".

It is not unambiguous with givens in scope, so Four is the same: overloading looks at signatures, not the use site.

@Gedochao
Copy link
Contributor

Gedochao commented Jan 16, 2025

Further, the errors reported by the compiler should be consistent across scala-cli and scalac.

Re-raised separately as VirtusLab/scala-cli#3430.
Guessing at a Bloop/Zinc error, needs investigation.
cc @tgodzik

@Gedochao Gedochao added area:implicits related to implicits area:runner Issues tied to the scala runner command. and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:runner Issues tied to the scala runner command. itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants