metals icon indicating copy to clipboard operation
metals copied to clipboard

Debug watch throws NoSuchElementException

Open asarkar opened this issue 1 year ago • 5 comments

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.

Screenshot 2024-09-08 at 5 50 00 PM

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

asarkar avatar Sep 09 '24 00:09 asarkar

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.

tgodzik avatar Sep 10 '24 10:09 tgodzik

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.

github-actions[bot] avatar Oct 11 '24 10:10 github-actions[bot]

What more information is required?

asarkar avatar Oct 11 '24 14:10 asarkar

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

tgodzik avatar Oct 11 '24 14:10 tgodzik

Thanks for reopening the ticket. I think I’ll wait for a stable version, no rush. Snapshot might fix this problem but introduce another.

asarkar avatar Oct 11 '24 15:10 asarkar

Are you able to reproduce it in 1.4.0 Metals version?

tgodzik avatar Oct 31 '24 12:10 tgodzik

I still am able to reproduce it using 1.4.0 Metals and VSCode 1.95.1

asarkar avatar Nov 01 '24 23:11 asarkar

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.

tgodzik avatar Nov 04 '24 09:11 tgodzik

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.

adpi2 avatar Nov 04 '24 13:11 adpi2

Looks like this is expected and work as intended. Thanks @adpi2 for adding the additional info.

tgodzik avatar Nov 04 '24 14:11 tgodzik