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

Tab completion after def results in an NPE #257

Closed
edwardsmatt opened this Issue Nov 12, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@edwardsmatt
Contributor

edwardsmatt commented Nov 12, 2015

If you type def and hit tab to invoke completion (without a space) a Null Pointer Exception occurs and Ammonite exits.

For example:

Loading...
Welcome to the Ammonite Repl 0.4.8
(Scala 2.11.7 Java 1.8.0_65)
matt-matt@ defException in thread "main" java.lang.NullPointerException

The full stack trace can be seen in the attached file.
amm-def-tab-npe.txt

lihaoyi added a commit that referenced this issue Nov 17, 2015

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Nov 17, 2015

This wasn't actually fixed it seems.

@edwardsmatt

This comment has been minimized.

Contributor

edwardsmatt commented Nov 17, 2015

Interesting, when running head using sbt shell/test:run or repl/run def<tab> doesn't result in a NPE for me. Do you have any further instructions on how you're reproducing this so I can follow up?

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Nov 17, 2015

I ran the standalone distribution https://github.com/lihaoyi/Ammonite/releases/tag/0.4.9, which should have your things in it because I merged your stuff earlier? Unless I screwed it up...

@edwardsmatt

This comment has been minimized.

Contributor

edwardsmatt commented Nov 17, 2015

No worries, I just checked the source for that standalone distribution and the fix isn't in there. So I suppose it just wasn't included in the distribution. See the diff:

git diff 0.4.9..HEAD

diff --git a/repl/src/main/scala/ammonite/repl/interp/Pressy.scala b/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
index b94183f..b8db3fb 100644
--- a/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
+++ b/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
@@ -203,27 +212,29 @@ object Pressy {
     def complete(snippetIndex: Int, previousImports: String, snippet: String) = {
       val prefix = previousImports + "\nobject AutocompleteWrapper{\n"
       val suffix = "\n}"
-      val allCode =  prefix + snippet + suffix
+      val allCode = prefix + snippet + suffix
       val index = snippetIndex + prefix.length
       if (cachedPressy == null) cachedPressy = initPressy

       val pressy = cachedPressy
       val currentFile = new BatchSourceFile(
         Compiler.makeFile(allCode.getBytes, name = "Current.scala"),
-        allCode
-      )
+        allCode)

       val r = new Response[Unit]
       pressy.askReload(List(currentFile), r)
       r.get.fold(x => x, e => throw e)

-      val run = new Run(pressy, currentFile, allCode, index)
+      val run = Try(new Run(pressy, currentFile, allCode, index))

-      val (i, all) = run.prefixed
+      val (i, all): (Int, Seq[(String, Option[String])]) = run match {
+        case Success(runSuccess) => runSuccess.prefixed
+        case Failure(throwable) => (0, Seq.empty)
+      }

-      val allNames = all.collect{ case (name, None) => name}.sorted.distinct
+      val allNames = all.collect { case (name, None) => name }.sorted.distinct

-      val signatures = all.collect{ case (name, Some(defn)) => defn }.sorted.distinct
+      val signatures = all.collect { case (name, Some(defn)) => defn }.sorted.distinct

       (i - prefix.length, allNames, signatures)
     }

(I thought I was going insane), because I reproduced it with a failing test before I fixed it 👍

It also appears the tests weren't included:

diff --git a/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala b/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
index 999fc42..efdf7d4 100644
--- a/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
+++ b/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
@@ -132,6 +132,8 @@ object AutocompleteTests extends TestSuite{
             "def >(x: Byte): Boolean"
           ) ^
         )
+
+
         // https://issues.scala-lang.org/browse/SI-9153
         //
         //      complete("""val x = 123; x + x.m<caret>""",
@@ -145,6 +147,14 @@ object AutocompleteTests extends TestSuite{
         //      complete("""Seq(1, 2, 3).map(_.co<caret>mpa)""", compares ^)
         //      complete("""Seq(1, 2, 3).map(_.<caret>compa)""", compares, ^)
       }
+      'defTab {
+        //Assert no NullPointerException was thrown. Does not verify any completions.
+        complete( """def<caret>""", Set.empty -- _)
+      }
+      'Array {
+        //Test around https://github.com/lihaoyi/Ammonite/issues/252
+        complete("""new Array<caret>""", Set() ^)
+      }
     }
   }
 }
@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Nov 17, 2015

Ah ok, I must have borked the release then, maybe I forgot to pull after merging your stuff on the website. It'll go out next release then =)

@lihaoyi lihaoyi closed this Nov 17, 2015

@edwardsmatt

This comment has been minimized.

Contributor

edwardsmatt commented Nov 17, 2015

👍 👍

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