Search code examples
scalascala-compiler

presentation compiler: type completion in method call with more than one argument


I load source into compiler with askReload, and then i try to call askTypeCompletion after . (dot). Completion in first case (method with 2 arguments) is not working, but completion in method call with one arg works as expected.

  val list = Seq(1,2)
  def add(x: Int, y: Int): Int = x + y
  def minusOne(x: Int) = x - 1


  add(list.<completion is not working)
  minusOne(list.<works fine>)

what's interesting is if i have code:

  implicit class OptionW[T](opt: Option[T]) {
    def cata[A](some: T => A, none: A) = opt.map(some) getOrElse none
  }


  Option("").cata(x => x.<not working>)

completion after dot is not working again, but if i type comma after dot and then try again to complete after dot, it works: Option("").cata(x => x.<works!>,) Is it some bug or expected behaviour?


Solution

  • I've prototyped a change to the compiler to be more fault tolerant of missing arguments.

    https://github.com/retronym/scala/commit/c1460f50945a161599d6d454da355ee20aa402b2

    Rather than simply bailing out with the "not enough arguments" error, we can also typecheck the given arguments if we have resolved to a single (non-overloaded) method. We need to typecheck the argument x => x.... using the parameter type as the expected type in order to infer the lambda parameter type, and in turn to offer completions.

    I've lodged this as an enhancement: https://issues.scala-lang.org/browse/SI-8739