Skip to content

REPL won't tell me the parameters with multiple completion candidates #12843

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

Closed
som-snytt opened this issue Aug 13, 2023 · 4 comments · Fixed by scala/scala#11035
Closed

REPL won't tell me the parameters with multiple completion candidates #12843

som-snytt opened this issue Aug 13, 2023 · 4 comments · Fixed by scala/scala#11035

Comments

@som-snytt
Copy link

Reproduction steps

Scala version: 2.13.11

scala> b.update()
               ^
       error: not enough arguments for method update: (index: Int, elem: String): Unit.
       Unspecified value parameters index, elem.

scala> b.update
         ^
       error: missing argument list for method update in class ArrayBuffer
       Unapplied methods are only converted to functions when a function type is expected.
       You can make this conversion explicit by writing `update _` or `update(_,_)` instead of `update`.

Problem

I'd like to see the signature without attempting an invocation. (Because who knows what may happen.)

It would be nice if missing argument list just told me the signature if unique, or that there are overloads.

Completion no longer tells me parameters when there are multiple completion candidates. (This used to be offered on subsequent tab.)

In this case, update and updated are candidates.

It does report signatures of a single completion candidate with overloads:

def remove(index: Int, count: Int): Unit
def remove(index: Int): String

scala> b.remove
@SethTisue
Copy link
Member

Yeah, this has long bugged me.

@som-snytt
Copy link
Author

som-snytt commented Mar 31, 2025

First tab

Image

Second tab to select with enter

Image

Third tab to show it above the prompt (instead of below?)

Image

Fourth tab to select updated instead then fifth tab for sig (actually I've lost track of the tabs while pasting screen shots)

Image

The carefully curated IOOBE is different for updated:

scala> b.updated(0, 42)
java.lang.IndexOutOfBoundsException: 0
  at scala.collection.SeqOps.updated(Seq.scala:956)
  at scala.collection.SeqOps.updated$(Seq.scala:953)
  at scala.collection.AbstractSeq.updated(Seq.scala:1190)
  ... 30 elided

scala> b.update(0, 42)
java.lang.IndexOutOfBoundsException: 0 is out of bounds (min 0, max -1)
  at scala.collection.generic.CommonErrors$.indexOutOfBounds(CommonErrors.scala:23)
  at scala.collection.mutable.ListBuffer.update(ListBuffer.scala:207)
  ... 30 elided

The behavior is similar but the signature is different on 3.6.4:

scala> val b = collection.mutable.ListBuffer.empty[Int]
val b: scala.collection.mutable.ListBuffer[Int] = ListBuffer()

def update(idx: Int, elem: A): Unit

def updated[B >: A](index: Int, elem: B): CC[B]

scala> b.updated

Less convenient 2.12 does not tab through alternatives, so you must finish typing it yourself and then tab for sig:

Welcome to Scala 2.12.20 (OpenJDK 64-Bit Server VM, Java 23.0.2).
Type in expressions for evaluation. Or try :help.

scala> val b = collection.mutable.ListBuffer.empty[Int]
b: scala.collection.mutable.ListBuffer[Int] = ListBuffer()

scala> b.update
update   updated

scala> b.update
   def update(n: Int,x: Int): Unit

scala> b.update
   def update(n: Int,x: Int): Unit

scala> b.updated

def updated[B >: Int, That](index: Int,elem: B)(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.mutable.ListBuffer[Int],B,That]): That

scala> b.updated

I don't know that I was right that the behavior used to be different: for a single completion candidate, tab shows sigs of all overloads. If more than one completion candidate, you must complete before viewing sigs. (Edit: it works that way in 2.13.11, so I don't know what my problem was.)

My other observation was that it doesn't show the sig of a missing arg list, but will show sigs of ambiguous overload, which is somehow ironic:

scala> b.remove
         ^
       error: ambiguous reference to overloaded definition,
       both method remove in class ListBuffer of type (idx: Int, count: Int): Unit
       and  method remove in class ListBuffer of type (idx: Int): Int
       match expected type ?

scala> b.update
         ^
       error: missing argument list for method update in class ListBuffer
       Unapplied methods are only converted to functions when a function type is expected.
       You can make this conversion explicit by writing `update _` or `update(_,_)` instead of `update`.

Maybe I will keep this open just for that part; maybe that's what bugged Seth and not the tab behavior.

@som-snytt
Copy link
Author

The foulest check file:

test/files/run/t12720.check:newSource1.scala:14: error: missing argument list for method f*** in class D***

@som-snytt
Copy link
Author

The other point is that the method may be overloaded even if an alternative has been selected.

t13055.scala:15: error: missing argument list for method forAll in object Main of type [T1, P](g: Main.Gen[T1])(f: T1 => P)(implicit p: P => Main.Prop): Main.Prop

because the source looks like

  def forAll[T1, P](g: Gen[T1])(f: T1 => P)(implicit p: P => Prop): Prop = ???
  def forAll[A1, P](f: A1 => P)(implicit p: P => Prop): Prop = ???

where the current message is unhelpful (or at least unhintful).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants