Skip to content

scala-cli repl --watch/restart crashes after recompiling sources #2851

Open
@josefwegner

Description

@josefwegner

Version(s)
Scala CLI version: 1.2.2

Describe the bug
Exiting a repl session with CTRL-C or :exit crashes after re-compiling changed sources

To Reproduce

 mkdir test
 cd test
 echo '@main def hello: Unit =\n    println("Hello, world\\n")' > hello.scala
 scala-cli repl --watch .

Exit the repl with CTRL-C results in following error message:

Exception in thread "main" com.sun.jna.LastErrorException: [5] Eingabe-/Ausgabefehler
        at com.sun.jna.Native.invokeVoid(Native Method)
        at com.sun.jna.Function.invoke(Function.java:415)
        at com.sun.jna.Function.invoke(Function.java:361)
        at com.sun.jna.Library$Handler.invoke(Library.java:265)
        at jdk.proxy1/jdk.proxy1.$Proxy0.tcsetattr(Unknown Source)
        at org.jline.terminal.impl.jna.linux.LinuxNativePty.doSetAttr(LinuxNativePty.java:89)
        at org.jline.terminal.impl.AbstractPty.setAttr(AbstractPty.java:29)
        at org.jline.terminal.impl.AbstractPosixTerminal.doClose(AbstractPosixTerminal.java:76)
        at org.jline.terminal.impl.PosixSysTerminal.doClose(PosixSysTerminal.java:95)
        at org.jline.terminal.impl.AbstractTerminal.close(AbstractTerminal.java:98)
        at dotty.tools.repl.JLineTerminal.close(JLineTerminal.scala:78)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:174)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:135)
        at dotty.tools.repl.Main$.main(Main.scala:7)
        at dotty.tools.repl.Main.main(Main.scala)

Same exceptions happens a bit later when you exit the repl with :exit and changing the source file:

scala-cli repl --watch .
Welcome to Scala 3.4.1 (17.0.10, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                           
scala> :exit
Watching sources, press Ctrl+C to exit, or press Enter to re-run.
Compiling project (Scala 3.4.1, JVM (17))
Compiled project (Scala 3.4.1, JVM (17))
Welcome to Scala 3.4.1 (17.0.10, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala>

After pressing any key, you get the exception:

Exception in thread "main" com.sun.jna.LastErrorException: [5] Eingabe-/Ausgabefehler
        at com.sun.jna.Native.invokeVoid(Native Method)
        at com.sun.jna.Function.invoke(Function.java:415)
        at com.sun.jna.Function.invoke(Function.java:361)
        at com.sun.jna.Library$Handler.invoke(Library.java:265)
        at jdk.proxy1/jdk.proxy1.$Proxy0.tcsetattr(Unknown Source)
        at org.jline.terminal.impl.jna.linux.LinuxNativePty.doSetAttr(LinuxNativePty.java:89)
        at org.jline.terminal.impl.AbstractPty.setAttr(AbstractPty.java:29)
        at org.jline.terminal.impl.AbstractPosixTerminal.doClose(AbstractPosixTerminal.java:76)
        at org.jline.terminal.impl.PosixSysTerminal.doClose(PosixSysTerminal.java:95)
        at org.jline.terminal.impl.AbstractTerminal.close(AbstractTerminal.java:98)
        at dotty.tools.repl.JLineTerminal.close(JLineTerminal.scala:78)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:174)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:135)
        at dotty.tools.repl.Main$.main(Main.scala:7)
        at dotty.tools.repl.Main.main(Main.scala)

Expected behaviour
Repl should properly restart after recompiling the project.

Running ammonite instead of the default repl does not have the same issue. Ammonite restarts properly after recompiling the code. But the input is messed up, you need to press the same key multiple times until it is printed in the repl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    --watchIssues tied to watching sourcesREPLIssues tied with the repl sub-command.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions