elvish: The `eq` command fails to correctly compare exception objects

There was a recent discussion on the IM channels about how to deal with the exception raised by builtins like break, continue, and return. That caused me to notice that this fails to produce the expected, true, result:

elvish> var e = ?(break)
elvish> eq ?(break) $e
▶ $false

That is, obviously, a contrived and not particularly interesting example in isolation. But it illustrates that the eq command fails to correctly compare exception objects such as raised by the control flow builtins. Which makes it impossible for examples like this (again, contrived and simplified) to work as expected:

elvish> try { break } catch e { if (eq ?(break) $e) { put "break captured" } }

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (21 by maintainers)

Most upvoted comments

I hoped that it would be. Backtrace data is not included in the documentation, so this comment means I agree with you that it should not be included in the comparison. It may be a nice thing to expose that data in the pseudo-map, and then documentation would change, of course, but that wouldn’t change my mind about comparison. I also can’t imagine any scenario where comparing backtrace data would be useful. Doing that would be effectively an identity check, and we have a separate function for that - is.

However, I stand by my statement.

It sounds like you’re arguing. Who are you arguing with?

Note also this example that unexpectedly outputs $false

Not unexpectedly (for now at least), it’s effectively the same example as in your first post in this issue, putting it in one line changes nothing.

You are right, of course. There were just two words too much, and I don’t know why I’ve put those there:

I think that comparing exceptions with eq should work simply by comparing types of reason fields as documented here.

It seems relevant here to mention this issue:

Exception control: “try” should rethrow flow control exceptions #1396

After all, one reason for trying to compare exceptions is to recognize flow control exceptions happening in a try block so one can rethrow them.