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 fresh name crash on first line of session #7934

Closed
som-snytt opened this issue Jan 8, 2020 · 4 comments · Fixed by #8221
Closed

REPL fresh name crash on first line of session #7934

som-snytt opened this issue Jan 8, 2020 · 4 comments · Fixed by #8221

Comments

@som-snytt
Copy link
Contributor

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)
@joroKr21
Copy link
Member

joroKr21 commented Jan 8, 2020

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

@som-snytt
Copy link
Contributor Author

som-snytt commented Jan 9, 2020

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.

@abgruszecki
Copy link
Contributor

See #8098 for an alternative reproduction.

@som-snytt
Copy link
Contributor Author

som-snytt commented Feb 6, 2020

PR for ParseResult.

This contribution doubles my productivity to 2 LOC/month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants