Debug watch throws NoSuchElementException
Describe the bug
object AtbashCipher:
private val mapping = ('a' to 'z').toIndexedSeq
def encode(plain: String): String =
val cipher = xcode(plain, mapping.size - 1 - _ + 'a')
cipher.grouped(5).mkString(" ")
def decode(cipher: String): String =
xcode(cipher, 'z' - _)
private def xcode(s: String, f: Char => Int): String =
val text = for c <- s; x = f(c.toLower); if c.isLetterOrDigit
yield (if c.isDigit then c else mapping(x))
text.mkString
When a breakpoint is put on the line yield, and variables c and x added to the watch, the panel throws NoSuchElementException. See screenshot below.
Expected behavior
Watch panel should be able to evaluate expressions.
Operating system
macOS
Editor/Extension
VS Code
Version of Metals
v1.3.5
Extra context or search terms
VSCode version 1.93.0 Scala version 3.4.2 JDK Version 21.0.4
This works for me on the newest snapshot of Metals, so this might have actually been already fix. I will try and release a new version of metals soon.
This issue was closed because no new information was added for the last 30 days. If you have any relevant information, feel free to add it and reopen the issue.
What more information is required?
Ach, I think I forgot to write if you could check the snapshot versions. I was supposed to release a new version, but I keep finding bugs to fix
Thanks for reopening the ticket. I think I’ll wait for a stable version, no rush. Snapshot might fix this problem but introduce another.
Are you able to reproduce it in 1.4.0 Metals version?
I still am able to reproduce it using 1.4.0 Metals and VSCode 1.95.1
Looks like the reason for it is that first stop is not inside the for, but outside of it. @adpi2 any idea is that expected? Might be limitation.
Looks like the reason for it is that first stop is not inside the for, but outside of it. @adpi2 any idea is that expected? Might be limitation.
Yes the issue is the compiler declares a debug line on the instantiation of the lambda.
In this example:
xs.map { x =>
x + 1
}
The compiler creates 3 debug lines: one on map, one on x => x + 1 and another one on x + 1. When you stop on x => x + 1, you cannot evaluate x, because it does not exist yet, hence the NoSuchElementException.
Looks like this is expected and work as intended. Thanks @adpi2 for adding the additional info.