Comments in scala repl paste mode

Does the scala repl support comments in :paste mode?

I’m just starting out with scala and was suprised by this interaction:

scala> :paste
// Entering paste mode (ctrl-D to finish)

// This is a comment
val x = 1

// Exiting paste mode, now interpreting.

scala> x
       ^
       error: not found: value x

If I do the same thing without the comment before the val x = 1 line, x is defined as expected. Not sure why there’s no error message when the comment is there.

I am running scala version:
Scala code runner version 2.13.2 – Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.

1 Like

Are you sure there is a proper end of line between the comment and the val?

Yes, I’m sure. At least without somehow inspecting the actual bytes that scala is receiving from my terminal I’m sure. I’m hitting return after the comment.

The same behaviour happens with a file. In which case we can do a hexdump:

$ xxd PasteTest.scala 
00000000: 2f2f 2054 6869 7320 6973 2061 2063 6f6d  // This is a com
00000010: 6d65 6e74 0a76 616c 2078 203d 2031 0a    ment.val x = 1.

We can see the newline character in the file. (Byte 0x0a, the convention for Linux, right?).

scala> :paste PasteTest.scala
Pasting file PasteTest.scala...

scala> x
       ^
       error: not found: value x

Maybe there’s something screwed with my setup. Not sure, but I doubt it.

So in general it should be working ok? We would expect :paste mode to handle comments at the start of the file?

1 Like

Scala 2.13.2 comes with a new line reader. This looks like a bug in it to me. I reported it here: https://github.com/scala/bug/issues/11991

2 Likes

Thanks for reporting it!

Nice catch! Definitely a blocker for 2.13.3.