REPL reports NPE when partially applied function is called in a semicolon delimited statement
See original GitHub issueHaving a function defined in REPL like in example below:
def bar: Int => Int => Int = a => b => a + b
the following statements are evaluated to NPE:
val b = bar(1);b(2)
java.lang.NullPointerException
at rs$line$2$.<init>(rs$line$2:1)
at rs$line$2$.<clinit>(rs$line$2)
at rs$line$2.res0Show(rs$line$2)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at dotty.tools.repl.Rendering.valueOf(Rendering.scala:58)
at dotty.tools.repl.Rendering.renderVal(Rendering.scala:79)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$8(ReplDriver.scala:269)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at dotty.tools.repl.ReplDriver.displayMembers$1(ReplDriver.scala:269)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$15(ReplDriver.scala:296)
at scala.Option.map(Option.scala:146)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$13(ReplDriver.scala:294)
at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:26)
at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:36)
at dotty.tools.dotc.core.Phases.atPhase$(Phases.scala:35)
at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:57)
at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:289)
at dotty.tools.repl.ReplDriver.$anonfun$compile$2(ReplDriver.scala:226)
at scala.util.Either.fold(Either.scala:188)
at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:220)
at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:190)
at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:143)
at dotty.tools.repl.Main$.main(Main.scala:6)
at dotty.tools.repl.Main.main(Main.scala)
java.lang.NoClassDefFoundError: Could not initialize class rs$line$2$
at rs$line$2.bShow(rs$line$2)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at dotty.tools.repl.Rendering.valueOf(Rendering.scala:58)
at dotty.tools.repl.Rendering.renderVal(Rendering.scala:79)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$8(ReplDriver.scala:269)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at dotty.tools.repl.ReplDriver.displayMembers$1(ReplDriver.scala:269)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$15(ReplDriver.scala:296)
at scala.Option.map(Option.scala:146)
at dotty.tools.repl.ReplDriver.$anonfun$displayDefinitions$13(ReplDriver.scala:294)
at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:26)
at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:36)
at dotty.tools.dotc.core.Phases.atPhase$(Phases.scala:35)
at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:57)
at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:289)
at dotty.tools.repl.ReplDriver.$anonfun$compile$2(ReplDriver.scala:226)
at scala.util.Either.fold(Either.scala:188)
at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:220)
at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:190)
at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:143)
at dotty.tools.repl.Main$.main(Main.scala:6)
at dotty.tools.repl.Main.main(Main.scala)
Will try to figure it out and fix, any tips from main contributors are very welcome.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Scala | Partially Applied functions - GeeksforGeeks
Partially applied functions are helpful in minimizing a function which accepts many arguments to a function that accepts only some arguments.
Read more >Solutions to Exercises - Springer Link
An argument list is a round bracket-delimited and comma-separated list of zero or more expressions. An argument is one of these expressions whose...
Read more >Partial Function Application in Haskell - Carbon Five Blog
Partial function application refers to calling a multiple parameter function with less than its total number of parameters.
Read more >Drools Expert User Guide
A stateless session can be called like a function passing it some data and ... note that the usage of the semicolon as...
Read more >pmd/release_notes_old.md at master - GitHub
UnnecessarySemicolon reports semicolons that are unnecessary (so called "empty statements" and "empty declarations"). This new rule replaces the rule ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Methods definitions are not evaluated, they are just pretty printed to the user. Only
val
definitions are evaluated.The way I would try to solve this issue, is by looking at the code the REPL generates and see if there is something wrong with it. You should be able to do this by adding some debug code here: https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/repl/ReplDriver.scala#L221-L226
@allanrenucci If I understand correct, renderMethod is evaluated before vals
Can you give a hint, how to fix this ?