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

REPL crashes on code completion for a subtype of Selectable #16360

Closed
prolativ opened this issue Nov 17, 2022 · 4 comments · Fixed by #16371
Closed

REPL crashes on code completion for a subtype of Selectable #16360

prolativ opened this issue Nov 17, 2022 · 4 comments · Fixed by #16371
Labels
area:repl itype:bug itype:crash regression This worked in a previous version but doesn't anymore

Comments

@prolativ
Copy link
Contributor

Compiler version

Crashes in 3.2.1 and nightly (3.3.0-RC1-bin-20221115-e587a81-NIGHTLY)
There was no crash in 3.2.0

Minimized code

class Foo extends Selectable
val x = (new Foo).<TAB>

Output (click arrow to expand)

Exception in thread "main" java.lang.AssertionError: assertion failed: missing implicit parameter of type languageFeature.reflectiveCalls after typer at phase parser
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1009)
	at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:811)
	at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:121)
	at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:877)
	at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:811)
	at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:121)
	at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3531)
	at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3567)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3643)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3831)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4074)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3409)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3028)
	at dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1103)
	at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1134)
	at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:811)
	at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:121)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1206)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.$anonfun$9(Implicits.scala:1544)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.allImplicits(Implicits.scala:1544)
	at dotty.tools.dotc.interactive.Completion$Completer.implicitConversionTargets(Completion.scala:513)
	at dotty.tools.dotc.interactive.Completion$Completer.implicitConversionMemberCompletions(Completion.scala:378)
	at dotty.tools.dotc.interactive.Completion$Completer.selectionCompletions(Completion.scala:320)
	at dotty.tools.dotc.interactive.Completion$.computeCompletions(Completion.scala:143)
	at dotty.tools.dotc.interactive.Completion$.completions(Completion.scala:48)
	at dotty.tools.repl.ReplDriver.completions$$anonfun$1(ReplDriver.scala:239)
	at scala.util.Either.map(Either.scala:382)
	at dotty.tools.repl.ReplDriver.completions(ReplDriver.scala:240)
	at dotty.tools.repl.ReplDriver.$anonfun$1(ReplDriver.scala:151)
	at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4412)
	at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4378)
	at org.jline.reader.impl.LineReaderImpl.expandOrComplete(LineReaderImpl.java:4317)
	at org.jline.reader.impl.LineReaderImpl$1.apply(LineReaderImpl.java:3809)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:679)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:468)
	at dotty.tools.repl.JLineTerminal.readLine(JLineTerminal.scala:74)
	at dotty.tools.repl.ReplDriver.readLine$1(ReplDriver.scala:156)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:166)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:171)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:191)
	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:179)
	at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:179)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:171)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:133)
	at dotty.tools.repl.Main$.main(Main.scala:7)
	at dotty.tools.repl.Main.main(Main.scala)
@prolativ prolativ added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label area:repl regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 17, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 18, 2022
@odersky
Copy link
Contributor

odersky commented Nov 18, 2022

What happened:

  1. We try to compute all completions accessible from conversions.
  2. The reflectiveSelectableFromLangReflectiveCalls conversion in class Selectable is in the implicit scope of Foo.
  3. That conversion needs a reflectiveCalls conversion, which triggers an implicit search.
  4. That implicit search went wrong before because phase parser does not allow implicit search.

Not sure which of these 4 elements was not present in 3.2.0.

@mpollmeier
Copy link
Contributor

Just in case anyone else runs into this: the linked PR also fixes a similar autocompletion error with chained implicits. Here's an example that worked in 3.2.0, crashes in 3.2.1 and works again in main since #16371 was merged:

class A
class B(a: A)
class C(b: B) { def foo = 42 }

implicit def toB(a: A): B = new B(a)
implicit def toCViaAdditionalImplicit(a: A)(implicit convertToB: A => B): C = new C(convertToB(a))

val a = new A
a.foo   // 42
a.<tab> //Exception in thread "main" java.lang.AssertionError: assertion failed: missing implicit parameter of type A => B after typer at phase parser

Thanks for reporting and fixing!

mpollmeier added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Nov 23, 2022
* those lead to trouble with autocompletion in Scala 3.2.1
* will be fixed in 3.2.2 - see scala/scala3#16360 (comment)
mpollmeier added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Nov 23, 2022
* comment out chained implicits temporarily

* those lead to trouble with autocompletion in Scala 3.2.1
* will be fixed in 3.2.2 - see scala/scala3#16360 (comment)

* make chained implicits available via explicit import
mpollmeier added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Nov 23, 2022
* also triggers autocompletion bug in repl
* will be fixed in 3.2.2 - see scala/scala3#16360 (comment)
* just like 74b874b
mpollmeier added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Nov 23, 2022
* also triggers autocompletion bug in repl
* will be fixed in 3.2.2 - see scala/scala3#16360 (comment)
* just like 74b874b
mpollmeier added a commit to ShiftLeftSecurity/overflowdb that referenced this issue Nov 23, 2022
* also triggers autocompletion bug in repl
* will be fixed in 3.2.2 - see scala/scala3#16360 (comment)
* just like 74b874b
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue Dec 22, 2022
@tedyu
Copy link

tedyu commented Jan 7, 2023

I was trying the following example from Dean's book with Scala 3.2.1 (I pressed TAB following toL)

scala> object Fib:
     |   val fibs: LazyList[BigInt] =
     |     BigInt(0) #:: BigInt(1) #:: fibs.zip(fibs.tail).map(n12 => n12._1 + n12._2)
     | Fib.fibs.take(5).toL
Exception in thread "main" java.lang.AssertionError: assertion failed: missing implicit parameter of type Ordering[LazyList[BigInt]] after typer at phase parser
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1006)
at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:808)
at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:121)

Looking forward to the release of 3.2.2 where the bug is fixed.

Thanks

@prolativ
Copy link
Contributor Author

prolativ commented Jan 9, 2023

@tedyu your problem is already fixed in 3.2.2-RC2

little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants