Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce or eliminate usage of non-local returns #552

Open
raquo opened this issue Mar 22, 2025 · 1 comment
Open

Reduce or eliminate usage of non-local returns #552

raquo opened this issue Mar 22, 2025 · 1 comment

Comments

@raquo
Copy link

raquo commented Mar 22, 2025

Semi-related to #519 by the goal of improving Scala.js debugging experience.

scala-java-time makes liberal use of non-local returns, e.g.:

      for (trans <- transArray) {
        info = findOffsetInfo(dt, trans)
        if (info.isLeft || (info == Right(trans.getOffsetBefore)))
          return info
      }

On the JS platform, Scala.js tries to compile non-local returns to native return and break, but this is not always possible, so they are sometimes compiled to use the NonLocalReturnControl exception.

This presents a problem for debugging Scala.js code in the browser, because you often want to use the Break on caught exceptions debugger option (e.g. to catch the origin of the exception in effect systems / observable graphs), but scala-java-time's NonLocalReturnControl exceptions trigger the debugger just as well in that case, and when working with date-heavy code, skipping through all those exceptions becomes unfeasible. I hoped that having fixed sourcemaps, I would be able to use the browser's "don't break here" option, but it does not seem to work, not sure why.

Also, nonlocal returns as a language feature are already throwing compiler deprecation warnings in Scala 3, so we do need a long term solution for that anyway.

With all that in mind, would you entertain a PR replacing nonlocal returns with equivalent constructs, e.g. while loops, else branches, etc.? There's a lot of such returns, I don't know if I can replace all of them, but I could at least get started on that.

@cquiroz
Copy link
Owner

cquiroz commented Mar 22, 2025

Seems a good idea, feel free to send a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants