com-lihaoyi / Ammonite

Scala Scripting
http://ammonite.io
MIT License
2.59k stars 365 forks source link

Error exits Ammonite shell when trying to look up methods for a Map object #1494

Open medale opened 1 month ago

medale commented 1 month ago

When using the . + tab gesture to look up methods on a Map[Int,Int] object from the Scala 3.3.3 shell, the action throws the error below and exits the Ammonite shell. Environment: Ubuntu 22.04 LTS with Amazon Corretto JDK 17.0.11. Works for lookups on String, Option[Int], List[Int] (but also fails for Map[String,String]).

Steps to replicate:

rm -Rf ~/.ammonite

curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/3.0.0-M2/3.3-3.0.0-M2-3-b5eb4787 > amm3

chmod +x amm3

./amm3
Welcome to the Ammonite Repl 3.0.0-M2-3-b5eb4787 (Scala 3.3.3 Java 17.0.11)

val m = Map(1 -> 2)
m. <hit tab for method lookup>
Exception in thread "main" java.lang.AssertionError: assertion failed: type error: Map[Int, Int] does not conform to scala.deriving.Mirror.ProductOf[T]I tried to show that
  Map[Int, Int]
conforms to
  scala.deriving.Mirror.ProductOf[T]
but the comparison trace ended with `false`:

  ==> Map[Int, Int]  <:  scala.deriving.Mirror.ProductOf[T]
    ==> Map[Int, Int]  <:  scala.deriving.Mirror.Product{   type MirroredType = T; type MirroredMonoType = T;     type MirroredElemTypes <: Tuple }
      ==> Map[Int, Int]  <:  scala.deriving.Mirror.Product{type MirroredType = T; type MirroredMonoType = T}
        ==> Map[Int, Int]  <:  scala.deriving.Mirror.Product{type MirroredType = T}
          ==> Map[Int, Int]  <:  scala.deriving.Mirror.Product
          <== Map[Int, Int]  <:  scala.deriving.Mirror.Product = false
        <== Map[Int, Int]  <:  scala.deriving.Mirror.Product{type MirroredType = T} = false
      <== Map[Int, Int]  <:  scala.deriving.Mirror.Product{type MirroredType = T; type MirroredMonoType = T} = false
    <== Map[Int, Int]  <:  scala.deriving.Mirror.Product{   type MirroredType = T; type MirroredMonoType = T;     type MirroredElemTypes <: Tuple } = false
  <== Map[Int, Int]  <:  scala.deriving.Mirror.ProductOf[T] = false

The tests were made under a constraint with:
 uninstantiated variables: T
 constrained types: [T](p: scala.deriving.Mirror.ProductOf[T]): Any
 bounds:
     T
 ordering:
 co-deps:
 contra-deps:

    at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
    at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1043)
    at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:819)
    at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:117)
    at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:857)
    at dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:819)
    at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:117)
    at dotty.tools.dotc.typer.Typer.adaptToSubType$1(Typer.scala:4168)
    at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:3996)
    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4071)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4277)
    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3590)
    at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
    at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
    at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
    at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
    at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
    at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
    at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
    at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
    at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
    at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
    at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:117)
    at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
    at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
    at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3327)
    at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)
    at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
    at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
    at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:117)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3050)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
    at dotty.tools.dotc.typer.Applications.extMethodApply(Applications.scala:2372)
    at dotty.tools.dotc.typer.Applications.extMethodApply$(Applications.scala:352)
    at dotty.tools.dotc.typer.Typer.extMethodApply(Typer.scala:117)
    at dotty.tools.dotc.typer.Applications.tryApplyingExtensionMethod(Applications.scala:2417)
    at dotty.tools.dotc.typer.Applications.tryApplyingExtensionMethod$(Applications.scala:352)
    at dotty.tools.dotc.typer.Typer.tryApplyingExtensionMethod(Typer.scala:117)
    at dotty.tools.dotc.interactive.Completion$Completer.tryApplyingReceiverToExtension$1(Completion.scala:392)
    at dotty.tools.dotc.interactive.Completion$Completer.$anonfun$15(Completion.scala:435)
    at scala.collection.immutable.List.flatMap(List.scala:294)
    at scala.collection.immutable.List.flatMap(List.scala:79)
    at dotty.tools.dotc.interactive.Completion$Completer.extensionCompletions(Completion.scala:438)
    at dotty.tools.dotc.interactive.Completion$Completer.selectionCompletions(Completion.scala:323)
    at dotty.ammonite.compiler.AmmCompletion$.computeCompletions(AmmCompletion.scala:45)
    at dotty.ammonite.compiler.AmmCompletion$.completions(AmmCompletion.scala:27)
    at ammonite.compiler.Compiler.complete(Compiler.scala:392)
    at ammonite.compiler.CompilerLifecycleManager.complete(CompilerLifecycleManager.scala:112)
    at ammonite.repl.Repl.action$$anonfun$2$$anonfun$2$$anonfun$1(Repl.scala:199)
    at ammonite.repl.Repl.action$$anonfun$2$$anonfun$2$$anonfun$adapted$1(Repl.scala:199)
    at ammonite.repl.AmmoniteFrontEnd.$anonfun$3(AmmoniteFrontEnd.scala:57)
    at ammonite.terminal.TTY$.withSttyOverride(Utils.scala:120)
    at ammonite.repl.AmmoniteFrontEnd.$anonfun$1(AmmoniteFrontEnd.scala:58)
    at ammonite.terminal.Filter$$anon$3$$anon$4.applyOrElse(Filter.scala:71)
    at ammonite.terminal.Filter$$anon$3$$anon$4.applyOrElse(Filter.scala:71)
    at scala.collection.IterableOnceOps.collectFirst(IterableOnce.scala:1256)
    at scala.collection.IterableOnceOps.collectFirst$(IterableOnce.scala:1248)
    at scala.collection.AbstractIterator.collectFirst(Iterator.scala:1303)
    at ammonite.terminal.Filter$$anon$3.op(Filter.scala:71)
    at ammonite.terminal.Filter$.ammonite$terminal$Filter$$anon$7$$_$op$$anonfun$3(Filter.scala:92)
    at scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
    at scala.collection.IterableOnceOps.find(IterableOnce.scala:677)
    at scala.collection.IterableOnceOps.find$(IterableOnce.scala:674)
    at scala.collection.AbstractIterator.find(Iterator.scala:1303)
    at ammonite.terminal.Filter$$anon$7.op(Filter.scala:92)
    at ammonite.terminal.LineReader.readChar(LineReader.scala:155)
    at ammonite.terminal.Terminal$.readLine$$anonfun$2(Terminal.scala:36)
    at ammonite.terminal.TTY$.withSttyOverride(Utils.scala:120)
    at ammonite.terminal.Terminal$.readLine(Terminal.scala:38)
    at ammonite.repl.AmmoniteFrontEnd.readLine(AmmoniteFrontEnd.scala:160)
    at ammonite.repl.AmmoniteFrontEnd.action(AmmoniteFrontEnd.scala:30)
    at ammonite.repl.Repl.action$$anonfun$2$$anonfun$2(Repl.scala:205)
    at ammonite.repl.Scoped.flatMap$$anonfun$1(Signaller.scala:45)
    at ammonite.repl.Signaller.apply(Signaller.scala:28)
    at ammonite.repl.Scoped.flatMap(Signaller.scala:45)
    at ammonite.repl.Scoped.flatMap$(Signaller.scala:42)
    at ammonite.repl.Signaller.flatMap(Signaller.scala:16)
    at ammonite.repl.Repl.action$$anonfun$2(Repl.scala:211)
    at ammonite.util.Res$Success.flatMap(Res.scala:58)
    at ammonite.repl.Repl.action(Repl.scala:211)
    at ammonite.repl.Repl.loop$1(Repl.scala:218)
    at ammonite.repl.Repl.run(Repl.scala:233)
    at ammonite.Main.run(Main.scala:249)
    at ammonite.MainRunner.runRepl$$anonfun$1(MainRunner.scala:76)
    at ammonite.MainRunner.watchLoop(MainRunner.scala:57)
    at ammonite.MainRunner.runRepl(MainRunner.scala:76)
    at ammonite.AmmoniteMain$.main0(AmmoniteMain.scala:98)
    at ammonite.AmmoniteMain$.main(AmmoniteMain.scala:31)
    at ammonite.AmmoniteMain.main(AmmoniteMain.scala)

Works for the 2.13 version so maybe this is a Scala 3.3.3 problem?

curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/3.0.0-M2/2.12-3.0.0-M2-3-b5eb4787 > amm2
chmod +x amm2
./amm2
Welcome to the Ammonite Repl 3.0.0-M2-3-b5eb4787 (Scala 2.13.14 Java 17.0.11)
val m = Map(1 -> 2) 
m. <+ tab>
+                   canEqual            count               filter              forall              grouped ...
medale commented 4 weeks ago

Running this from the scala shell on Mac works as expected:

scala-cli repl -S 3.3.3
Welcome to Scala 3.3.3 (17.0.11, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> val m = Map(1 -> 2)
val m: Map[Int, Int] = Map(1 -> 2)

scala> m. <hit tab for method lookup>
!=                   Maximized            contains

But not from Ammonite:

scala-cli repl -S 3.3.3 --amm --power
Welcome to the Ammonite Repl 3.0.0-M1-19-a7973e17 (Scala 3.3.3 Java 17.0.11)
@ val m = Map(1 -> 2)
m: Map[Int, Int] = Map(1 -> 2)

@ m.<hit tab for method lookup>
Exception in thread "main" java.lang.AssertionError: assertion failed: type error: Map[Int, Int] does not conform to scala.deriving.Mirror.ProductOf[T... (as above)