Dotty: REPL fresh name crash on first line of session

Created on 9 Jan 2020  Â·  4Comments  Â·  Source: lampepfl/dotty

minimized code

➜  ~ dotr
Starting dotty REPL...
scala> List(1) map (_ + 2) size 


Stack trace

Exception in thread "main" java.lang.NullPointerException
    at dotty.tools.dotc.core.NameKinds$UniqueNameKind.fresh(NameKinds.scala:218)
    at dotty.tools.dotc.parsing.Parsers$Parser.simpleExpr(Parsers.scala:2106)
    at dotty.tools.dotc.parsing.Parsers$Parser.$init$$$anonfun$7(Parsers.scala:2075)
    at dotty.tools.dotc.parsing.Parsers$Parser.postfixExpr(Parsers.scala:2059)
    at dotty.tools.dotc.parsing.Parsers$Parser.expr1(Parsers.scala:1920)
    at dotty.tools.dotc.parsing.Parsers$Parser.expr(Parsers.scala:1795)
    at dotty.tools.dotc.parsing.Parsers$Parser.$init$$$anonfun$5(Parsers.scala:1774)
    at dotty.tools.dotc.parsing.Parsers$Parser.tokenSeparated(Parsers.scala:591)
    at dotty.tools.dotc.parsing.Parsers$Parser.commaSeparated(Parsers.scala:599)
    at dotty.tools.dotc.parsing.Parsers$Parser.exprsInParensOpt(Parsers.scala:2196)
    at dotty.tools.dotc.parsing.Parsers$Parser.$anonfun$8(Parsers.scala:2112)
    at dotty.tools.dotc.parsing.Parsers$Parser.enclosed(Parsers.scala:559)
    at dotty.tools.dotc.parsing.Parsers$Parser.inParens(Parsers.scala:566)
    at dotty.tools.dotc.parsing.Parsers$Parser.simpleExpr(Parsers.scala:2112)
    at dotty.tools.dotc.parsing.Parsers$Parser.$init$$$anonfun$7(Parsers.scala:2075)
    at dotty.tools.dotc.parsing.Parsers$Parser.recur$3(Parsers.scala:1004)
    at dotty.tools.dotc.parsing.Parsers$Parser.infixOps(Parsers.scala:1017)
    at dotty.tools.dotc.parsing.Parsers$Parser.postfixExprRest(Parsers.scala:2062)
    at dotty.tools.dotc.parsing.Parsers$Parser.postfixExpr(Parsers.scala:2059)
    at dotty.tools.dotc.parsing.Parsers$Parser.expr1(Parsers.scala:1920)
    at dotty.tools.dotc.parsing.Parsers$Parser.expr(Parsers.scala:1795)
    at dotty.tools.dotc.parsing.Parsers$Parser.blockStatSeq$$anonfun$1(Parsers.scala:3786)
    at dotty.tools.dotc.parsing.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:500)
    at dotty.tools.dotc.parsing.Parsers$Parser.blockStatSeq(Parsers.scala:3798)
    at dotty.tools.repl.ParseResult$.parseStats(ParseResult.scala:113)
    at dotty.tools.repl.ParseResult$.isIncomplete$$anonfun$2(ParseResult.scala:165)
    at dotty.tools.dotc.reporting.Reporter.withIncompleteHandler(Reporter.scala:220)
    at dotty.tools.repl.ParseResult$.isIncomplete(ParseResult.scala:166)
    at dotty.tools.repl.JLineTerminal$Parser.acceptLine$1(JLineTerminal.scala:130)
    at dotty.tools.repl.JLineTerminal$Parser.parse(JLineTerminal.scala:134)
    at org.jline.reader.impl.LineReaderImpl.acceptLine(LineReaderImpl.java:2731)
    at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:585)
    at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:404)
    at dotty.tools.repl.JLineTerminal.readLine(JLineTerminal.scala:68)
    at dotty.tools.repl.ReplDriver.readLine$1(ReplDriver.scala:115)
    at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:125)
    at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
    at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
    at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
    at dotty.tools.repl.Main$.main(Main.scala:6)
    at dotty.tools.repl.Main.main(Main.scala)

It works on the second line:

➜  ~ dotr -version
Starting dotty REPL...
Dotty compiler version 0.21.0-RC1 -- Copyright 2002-2019, LAMP/EPFL
scala> 42                                                                             
val res0: Int = 42

scala> List(42)
val res1: List[Int] = List(42)

scala> List(42) map (_ + 1) size                                                      
val res2: Int = 1

I contrived a fairly trivial example to illustrate my point as follows:

➜  ~ dotr
Starting dotty REPL...
scala> _ + 1
Exception in thread "main" java.lang.NullPointerException
    at dotty.tools.dotc.core.NameKinds$UniqueNameKind.fresh(NameKinds.scala:218)
bug crash

Most helpful comment

Since only an underscore is required for the symptom, I hope they send me a dotty t-shirt for shortest crasher.

To follow up @joroKr21 the selection is ctx.compilationUnit.freshNames.newName.

➜  ~ dotr -J-XX:+ShowCodeDetailsInExceptionMessages
Starting dotty REPL...
scala> _                                                                              
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "dotty.tools.dotc.CompilationUnit.freshNames()" because the return value of "dotty.tools.dotc.core.Contexts$Context.compilationUnit()" is null
    at dotty.tools.dotc.core.NameKinds$UniqueNameKind.fresh(NameKinds.scala:218)

That really is a helpful NPE on JDK14.

All 4 comments

Perhaps there is no line yet for the virtual source file but couldn't find where exactly it is set.

Since only an underscore is required for the symptom, I hope they send me a dotty t-shirt for shortest crasher.

To follow up @joroKr21 the selection is ctx.compilationUnit.freshNames.newName.

➜  ~ dotr -J-XX:+ShowCodeDetailsInExceptionMessages
Starting dotty REPL...
scala> _                                                                              
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "dotty.tools.dotc.CompilationUnit.freshNames()" because the return value of "dotty.tools.dotc.core.Contexts$Context.compilationUnit()" is null
    at dotty.tools.dotc.core.NameKinds$UniqueNameKind.fresh(NameKinds.scala:218)

That really is a helpful NPE on JDK14.

See #8098 for an alternative reproduction.

PR for ParseResult.

This contribution doubles my productivity to 2 LOC/month.

Was this page helpful?
0 / 5 - 0 ratings