Dotty: Top level implicit class with no arguments crashes in messages

Created on 18 May 2017  路  10Comments  路  Source: lampepfl/dotty

The source

implicit class Foo

crashes with

Exception in thread "main" java.lang.IndexOutOfBoundsException: 0
    at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:65)
    at scala.collection.immutable.List.apply(List.scala:84)
    at dotty.tools.dotc.reporting.diagnostic.messages$TopLevelImplicitClass.<init>(messages.scala:355)
    at dotty.tools.dotc.ast.desugar$$anonfun$17.apply(Desugar.scala:475)
    at dotty.tools.dotc.ast.desugar$$anonfun$17.apply(Desugar.scala:475)
    at dotty.tools.dotc.reporting.diagnostic.MessageContainer.contained(MessageContainer.scala:59)
    at dotty.tools.dotc.reporting.diagnostic.MessageContainer.message(MessageContainer.scala:42)
    at dotty.tools.dotc.reporting.diagnostic.MessageContainer.isNonSensical(MessageContainer.scala:71)
    at dotty.tools.dotc.reporting.HideNonSensicalMessages$class.isHidden(HideNonSensicalMessages.scala:17)
    at dotty.tools.dotc.reporting.ConsoleReporter.isHidden(ConsoleReporter.scala:13)
    at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:232)
    at dotty.tools.dotc.reporting.Reporting$class.error(Reporter.scala:89)
    at dotty.tools.dotc.core.Contexts$Context.error(Contexts.scala:57)
    at dotty.tools.dotc.ast.desugar$.classDef(Desugar.scala:475)
    at dotty.tools.dotc.ast.desugar$.defTree(Desugar.scala:655)
    at dotty.tools.dotc.typer.Namer.expand(Namer.scala:364)
    at dotty.tools.dotc.typer.Namer$$anonfun$index$1.apply(Namer.scala:636)
    at dotty.tools.dotc.typer.Namer$$anonfun$index$1.apply(Namer.scala:636)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at dotty.tools.dotc.typer.Namer.index(Namer.scala:636)
    at dotty.tools.dotc.typer.Namer.dotty$tools$dotc$typer$Namer$$recur$1(Namer.scala:427)
    at dotty.tools.dotc.typer.Namer.indexExpanded(Namer.scala:444)
    at dotty.tools.dotc.typer.Namer.index(Namer.scala:417)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$enterSyms$1.apply$mcV$sp(FrontEnd.scala:52)
    at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
    at dotty.tools.dotc.typer.FrontEnd.enterSyms(FrontEnd.scala:50)
    at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:89)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:82)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:79)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:79)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:67)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:67)
    at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:67)
    at dotty.tools.dotc.Run.compileSources(Run.scala:64)
    at dotty.tools.dotc.Run.compile(Run.scala:48)
    at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
    at dotty.tools.dotc.Driver.process(Driver.scala:124)
    at dotty.tools.dotc.Driver.process(Driver.scala:93)
    at dotty.tools.dotc.Driver.process(Driver.scala:105)
    at dotty.tools.dotc.Driver.main(Driver.scala:132)
    at dotty.tools.dotc.Main.main(Main.scala)

novice help wanted bug low

All 10 comments

@nicolasstucki I'd love to take a dig at this. Could you give me a lead as to how to go about doing it? Thanks!

@Varunram to reproduce it just create the file tests/neg/i2463.scala with the code implicit class Foo then run sbt "vulpix i2463". The issue is in messages.scala:355 where there is an access to an empty list in constr0.vparamss(0).

It will probably be good enough if you replace the exampleArgs by "..." if there are no args.

@nicolasstucki Hate to trouble you again, but I'm kinda new to scala debugging so here goes. I tried doing val exampleArgs = if(constr0.vparamss(0).isEmpty) "..." else constr0.vparamss(0).map(_.withMods(untpd.Modifiers()).show).mkString(", ") but it presents the same output. Where am I going wrong? Thanks!

@Varunram vparamss is a list of lists, it might be the outer list that is empty. Therefore constr0.vparamss will be something like List(List("a"), List("b")). With your version you would be checking if List("a").isEmpty.

Another thing is that constr0.vparamss is a field or method that return a list of lists List[List[Something]] and not a method that receives an Int. Therefore the application of (0) will be done on the List, which in scala becomes a call on the List.apply method (i.e. get the element at index 0).

Try if(constr0.vparamss.isEmpty) "..." else.

@Varunram you can also quickly compile the test file using run tests/neg/i2463.scala, there you can see the error message.
Another thing is that you should add // error to the end of the line where we expect the error. This is tested when running with vulpix. The test file should be

implicit class Foo // error

Thanks for the info! Helps to check em faster. But I seem to get the same error after your fix too, Is is a problem on my side?

Same IndexOutOfBoundsException in messages.scala:355?

EDIT: Sorry, some weird problem on my side. Got

1 |implicit class Foo //error
  |^^^^^^^^^^^^^^^^^^
  |An implicit class may not be top-level

as expected. Thanks a ton!

Do I need to put in a PR? I feel you should commit it (if possible) since you guided me through

Was this page helpful?
0 / 5 - 0 ratings