-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Original discussion here: https://contributors.scala-lang.org/t/presentation-compiler-autocompletion-bug-with-dependent-types/897
This a bit of an edge case, I guess that's why it wasn't discovered yet: Autocompletion fails when using dependent types AND omitting the (empty) first parameter block. You can reproduce it in the repl as follows:
object Test1 {
trait Conv[In] {
type Out
def apply(in: In): Out
}
object Conv {
type Aux[In, Out0] = Conv[In] { type Out = Out0 }
implicit val int2String = new Conv[Int] {
type Out = String
override def apply(i: Int) = i.toString
}
}
def withParens[Out]()(implicit conv: Conv.Aux[Int, Out]): Out = "5".asInstanceOf[Out]
def withoutParens[Out](implicit conv: Conv.Aux[Int, Out]): Out = "5".asInstanceOf[Out]
}
Then type Test1.withParens().<TAB>
- it does find autocompletions for String. However, if you try Test1.withoutParens.<TAB>
it does not. As a workaround, when saving intermediate result, it works:
val a = Test1.withoutParens; a.<TAB>
Without dependent types, autocompletion works fine in both cases:
object Test2 {
trait A
implicit val a: A = ???
def withParens()(implicit a: A): String = "something"
def withoutParens(implicit a: A): String = "something"
}
The best solution would be to fix this in the presentation compiler, but I didn't manage to pin down the problem there. Instead, as a workaround, I patched the repl autocompletion - if it doesn't find any autocompletions, it interprets the code up until that point and then tries again. Here's a mini repo that's using the presentation compiler and the patched autocompletion:
https://github.com/mpollmeier/scala-presentation-compiler-autocomplete-fix-
If you use PresentationCompilerCompleter
instead of MyPresentationCompilerCompleter
in the test, you get the old behaviour (no autocompletion).
From @retronym:
I've prototyped a fix for the REPL autocompletion here: https://github.com/retronym/scala/tree/topic/completion-depmet-implicit
It needs a bit more work to see if the fix should really be pushed into typeMembers, rather than having the if/else in completionsAt. A good litmus test would be to try to reproduce the bug in Scala IDE. If that also fails to autocomplete, the root problem is likely in typeMembers, which is finding members of the type of the smallest tree that encloses the search position. There are two trees with the same range position:
ApplyImplicitArgs(Select(...), args)
, and locate finds the innerSelect
. Not sure why the dependent types figure into the equation yet.