NullPointerException when using IMain.bind()

I am trying to use the Scala interpreter (IMain) to bind an object to a variable. I am using Scala 2.13.6.

I create an IMain using:

private def initInterpreter: IMain = {
    val settings = new GenericRunnerSettings(println _)
    settings.usejavacp.value = true
    val flusher = new
    val replReporter = new ReplReporterImpl(settings, flusher)
    new IMain(settings, replReporter)

Then, I try to call bind() using:

interpreter = initInterpreter
var sample = 50
interpreter.bind("sample", "Int", sample)

When I do this, I get a NullPointerException:

java.lang.NullPointerException: null

I looked at the ReadEvalPrint and CompilationUnit source codes to try to see where the null is coming from, but it’s not clear to me.

Also, pardon the simple example – I am trying to get it to work for an Int before I use it for my own self-defined type.

Any suggestions?

➜  ~ scala -nobootcp
Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 15).
Type in expressions for evaluation. Or try :help.

scala> val sc =
val sc: =

scala> sc.intp.bind("foo", "String", "hello, world")
val res0: tools.nsc.interpreter.Results.Result = Success

scala> sc.intp.interpret("foo")
val res1: tools.nsc.interpreter.Results.Result = Success

scala> sc.intp.interpret("println(foo)")
hello, world
val res2: tools.nsc.interpreter.Results.Result = Success