Skip to content

Commit

Permalink
Fixes NPE on no-save-then-load situation
Browse files Browse the repository at this point in the history
  • Loading branch information
tkroman authored and lihaoyi committed Dec 9, 2016
1 parent 3119490 commit 4032eee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Expand Up @@ -743,4 +743,4 @@ object Interpreter{
)
(colors, printStream, errorPrintStream, printer)
}
}
}
4 changes: 2 additions & 2 deletions amm/repl/src/main/scala/ammonite/repl/ApiImpls.scala
Expand Up @@ -41,6 +41,7 @@ class SessionApiImpl(eval: Evaluator) extends Session{
eval.frames = childFrame(next.head) :: next
out
}

def load(name: String = "") = {
val next = if (name == "") eval.frames.tail else namedFrames(name)
val out = SessionChanged.delta(eval.frames.head, next.head)
Expand All @@ -51,7 +52,6 @@ class SessionApiImpl(eval: Evaluator) extends Session{
def delete(name: String) = {
namedFrames.remove(name)
}
save()
}
class ReplApiImpl(val interp: Interpreter,
width0: => Int,
Expand Down Expand Up @@ -142,4 +142,4 @@ class ReplApiImpl(val interp: Interpreter,
}
}

}
}
15 changes: 8 additions & 7 deletions amm/repl/src/main/scala/ammonite/repl/Repl.scala
Expand Up @@ -38,10 +38,6 @@ class Repl(input: InputStream,
"""
}.mkString(newLine)





val interp: Interpreter = new Interpreter(
printer,
storage,
Expand All @@ -61,14 +57,19 @@ class Repl(input: InputStream,
history,
new SessionApiImpl(i.eval),
replArgs

)
Seq(("ammonite.repl.ReplBridge", "repl", replApi))
},
wd
)


// Call `session.save` _after_ the interpreter is fully instantiated and
// imports are loaded. We only need to do this in `Repl` and not in
// `Interpreter`, as using sess.save or load inside scripts is sketchy and
// probably not something we can support
interp.bridges.collectFirst {
case ("ammonite.repl.ReplBridge", _, r: ReplAPI) => r
}.foreach(_.sess.save())

val reader = new InputStreamReader(input)

Expand Down Expand Up @@ -157,4 +158,4 @@ object Repl{
)
traces.mkString(newLine)
}
}
}

0 comments on commit 4032eee

Please sign in to comment.